Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save trevershick/1082303 to your computer and use it in GitHub Desktop.
Save trevershick/1082303 to your computer and use it in GitHub Desktop.
package com.railinc.sso.zuul.legacy;
// imports removed
@RunWith(PowerMockRunner.class)
@SuppressStaticInitializationFor("com.netegrity.policyserver.smapi.ActiveExpressionContext")
public class GetAccessCookieActiveExpressionTest {
public ActiveExpressionContext build_nice_ae_context(UserContext uc, APIContext ac) {
ActiveExpressionContext c = createNiceMock(ActiveExpressionContext.class);
expect(c.getUserContext()).andReturn(uc);
expect(c.getAPIContext()).andReturn(ac);
return c;
}
public APIContext build_quiet_api_context() {
return createNiceMock(APIContext.class);
}
public UserContext build_happy_user_context_fixture() {
UserContext c = createNiceMock(UserContext.class);
return c;
}
@Test
public void test_happy() throws Exception {
// create fixtures
UserContext userContext = build_happy_user_context_fixture();
APIContext apiContext = build_quiet_api_context();
ActiveExpressionContext context = build_nice_ae_context(userContext, apiContext);
expect(userContext.getProp("givenName")).andReturn("yyy");
expect(userContext.getProp("sn")).andReturn("zzz");
expect(userContext.getProp("uid")).andReturn("XXXXXX");
expect(userContext.getProp("mail")).andReturn("[email protected]");
// replay and run test
replay(userContext, apiContext, context);
GetAccessCookieActiveExpression e = new GetAccessCookieActiveExpression();
e.init(apiContext);
String value = e.invoke(context, null);
value = new String(Base64.decodeBase64(value.getBytes()));
e.release(apiContext);
assertNotNull(value);
assertTrue("Should have my user id in the token", value.contains("XXXXXX"));
assertTrue("Should have my firstname in the token", value.contains("yyy"));
assertTrue("Should have my last name in the token", value.contains("zzz"));
assertTrue("Should have my escaped email in the token", value.contains("xxx@xxx\\.com"));
}
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>1.4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.4.9</version>
<scope>test</scope>
</dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment