Skip to content

Commit

Permalink
Test Refactor (AuthorizeEndpointDocs)
Browse files Browse the repository at this point in the history
- Upgrade to JUnit5

[#163154789] https://www.pivotaltracker.com/story/show/163154789

Signed-off-by: Jaskanwal Pawar <jpawar@pivotal.io>
Co-authored-by: Jaskanwal Pawar <jpawar@pivotal.io>
  • Loading branch information
joshuatcasey and Jaskanwal Pawar committed Jan 18, 2019
1 parent a0204e5 commit f327862
Showing 1 changed file with 19 additions and 12 deletions.
Expand Up @@ -11,21 +11,22 @@
import org.cloudfoundry.identity.uaa.user.UaaAuthority; import org.cloudfoundry.identity.uaa.user.UaaAuthority;
import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder; import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.jupiter.api.AfterEach;
import org.junit.Rule; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpSession; import org.springframework.mock.web.MockHttpSession;
import org.springframework.restdocs.JUnitRestDocumentation; import org.springframework.restdocs.ManualRestDocumentation;
import org.springframework.restdocs.request.ParameterDescriptor; import org.springframework.restdocs.request.ParameterDescriptor;
import org.springframework.restdocs.snippet.Snippet; import org.springframework.restdocs.snippet.Snippet;
import org.springframework.security.oauth2.common.util.RandomValueStringGenerator; import org.springframework.security.oauth2.common.util.RandomValueStringGenerator;
import org.springframework.security.web.FilterChainProxy; import org.springframework.security.web.FilterChainProxy;
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
Expand Down Expand Up @@ -54,7 +55,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


@RunWith(SpringJUnit4ClassRunner.class) @ExtendWith(SpringExtension.class)
@ActiveProfiles("default") @ActiveProfiles("default")
@WebAppConfiguration @WebAppConfiguration
@ContextConfiguration(classes = TestSpringContext.class) @ContextConfiguration(classes = TestSpringContext.class)
Expand All @@ -77,24 +78,30 @@ public class AuthorizeEndpointDocs {
@Autowired @Autowired
private FilterChainProxy springSecurityFilterChain; private FilterChainProxy springSecurityFilterChain;


@Rule private ManualRestDocumentation restDocumentation = new ManualRestDocumentation("build/generated-snippets");
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/generated-snippets");


@Before @BeforeEach
public void setUp() throws Exception { public void setUp(TestInfo testInfo) throws Exception {
ScimUser marissa = userProvisioning.query("username eq \"marissa\" and origin eq \"uaa\"", IdentityZoneHolder.get().getId()).get(0); ScimUser marissa = userProvisioning.query("username eq \"marissa\" and origin eq \"uaa\"", IdentityZoneHolder.get().getId()).get(0);
UaaPrincipal uaaPrincipal = new UaaPrincipal(marissa.getId(), marissa.getUserName(), marissa.getPrimaryEmail(), marissa.getOrigin(), marissa.getExternalId(), IdentityZoneHolder.get().getId()); UaaPrincipal uaaPrincipal = new UaaPrincipal(marissa.getId(), marissa.getUserName(), marissa.getPrimaryEmail(), marissa.getOrigin(), marissa.getExternalId(), IdentityZoneHolder.get().getId());
principal = new UaaAuthentication(uaaPrincipal, Collections.singletonList(UaaAuthority.fromAuthorities("uaa.user")), null); principal = new UaaAuthentication(uaaPrincipal, Collections.singletonList(UaaAuthority.fromAuthorities("uaa.user")), null);


restDocumentation.beforeTest(testInfo.getTestClass().get(), testInfo.getDisplayName());
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
.addFilter(springSecurityFilterChain) .addFilter(springSecurityFilterChain)
.apply(documentationConfiguration(restDocumentation) .apply(documentationConfiguration(restDocumentation)
.uris().withPort(80).and() .uris().withPort(80)
.and()
.snippets() .snippets()
.withTemplateFormat(markdown())) .withTemplateFormat(markdown()))
.build(); .build();
} }


@AfterEach
public void teardownRestDocumentationContext() {
restDocumentation.afterTest();
}

@Test @Test
public void browserCodeRequest() throws Exception { public void browserCodeRequest() throws Exception {
MockHttpSession session = new MockHttpSession(); MockHttpSession session = new MockHttpSession();
Expand Down

0 comments on commit f327862

Please sign in to comment.