use of com.opensymphony.xwork2.mock.MockInterceptor in project struts by apache.
the class ConfigurationTest method testInterceptorParamOverride.
public void testInterceptorParamOverride() {
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", "TestInterceptorParamOverride", null, null);
assertEquals(1, proxy.getConfig().getInterceptors().size());
MockInterceptor testInterceptor = (MockInterceptor) proxy.getConfig().getInterceptors().get(0).getInterceptor();
assertEquals("foo123", testInterceptor.getExpectedFoo());
proxy.execute();
assertTrue(testInterceptor.isExecuted());
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.opensymphony.xwork2.mock.MockInterceptor in project struts by apache.
the class DefaultActionInvocationTester method testInvoke.
/**
* Tests interceptor chain invoke.
*
* @throws Exception when action throws exception
*/
public void testInvoke() throws Exception {
List<InterceptorMapping> interceptorMappings = new ArrayList<>();
MockInterceptor mockInterceptor1 = new MockInterceptor();
mockInterceptor1.setFoo("test1");
mockInterceptor1.setExpectedFoo("test1");
interceptorMappings.add(new InterceptorMapping("test1", mockInterceptor1));
MockInterceptor mockInterceptor2 = new MockInterceptor();
interceptorMappings.add(new InterceptorMapping("test2", mockInterceptor2));
mockInterceptor2.setFoo("test2");
mockInterceptor2.setExpectedFoo("test2");
MockInterceptor mockInterceptor3 = new MockInterceptor();
interceptorMappings.add(new InterceptorMapping("test3", mockInterceptor3));
mockInterceptor3.setFoo("test3");
mockInterceptor3.setExpectedFoo("test3");
DefaultActionInvocation defaultActionInvocation = new DefaultActionInvocationTester(interceptorMappings);
container.inject(defaultActionInvocation);
defaultActionInvocation.stack = container.getInstance(ValueStackFactory.class).createValueStack();
// is possible when result is not executed already
defaultActionInvocation.setResultCode("");
defaultActionInvocation.invoke();
assertTrue(mockInterceptor1.isExecuted());
assertTrue(mockInterceptor2.isExecuted());
assertTrue(mockInterceptor3.isExecuted());
assertTrue(defaultActionInvocation.isExecuted());
try {
defaultActionInvocation.setResultCode("");
fail("should not possible when result already executed");
} catch (Exception ignored) {
}
try {
defaultActionInvocation.invoke();
fail("should not possible when result already executed");
} catch (Exception ignored) {
}
}
use of com.opensymphony.xwork2.mock.MockInterceptor in project struts by apache.
the class XmlConfigurationProviderInterceptorsTest method testInterceptorParamOverriding.
public void testInterceptorParamOverriding() throws Exception {
Map<String, String> params = new HashMap<>();
params.put("foo", "expectedFoo");
params.put("expectedFoo", "expectedFooValue");
InterceptorStackConfig defaultStack = new InterceptorStackConfig.Builder("defaultStack").addInterceptor(new InterceptorMapping("noop", objectFactory.buildInterceptor(noopInterceptor, new HashMap<String, String>()))).addInterceptor(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptor, params))).build();
ArrayList<InterceptorMapping> interceptors = new ArrayList<>();
interceptors.addAll(defaultStack.getInterceptors());
ActionConfig intAction = new ActionConfig.Builder("", "TestInterceptorParam", SimpleAction.class.getName()).addInterceptors(interceptors).build();
// TestInterceptorParamOverride action tests that an interceptor with a param override worked
HashMap<String, String> interceptorParams = new HashMap<>();
interceptorParams.put("expectedFoo", "expectedFooValue2");
interceptorParams.put("foo", "foo123");
InterceptorStackConfig defaultStack2 = new InterceptorStackConfig.Builder("defaultStack").addInterceptor(new InterceptorMapping("noop", objectFactory.buildInterceptor(noopInterceptor, new HashMap<String, String>()))).addInterceptor(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptor, interceptorParams))).build();
interceptors = new ArrayList<>();
interceptors.addAll(defaultStack2.getInterceptors());
ActionConfig intOverAction = new ActionConfig.Builder("", "TestInterceptorParamOverride", SimpleAction.class.getName()).addInterceptors(interceptors).build();
ConfigurationProvider provider = buildConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-interceptor-params.xml");
PackageConfig pkg = configuration.getPackageConfig("default");
Map actionConfigs = pkg.getActionConfigs();
// assertions
assertEquals(2, actionConfigs.size());
assertEquals(intAction, actionConfigs.get("TestInterceptorParam"));
assertEquals(intOverAction, actionConfigs.get("TestInterceptorParamOverride"));
ActionConfig ac = (ActionConfig) actionConfigs.get("TestInterceptorParamOverride");
assertEquals(defaultStack.getInterceptors(), ac.getInterceptors());
ActionConfig ac2 = (ActionConfig) actionConfigs.get("TestInterceptorParam");
assertEquals(defaultStack2.getInterceptors(), ac2.getInterceptors());
}
use of com.opensymphony.xwork2.mock.MockInterceptor in project aws-cloud-meta by prisma-capacity.
the class ECSMetaDataReaderIntegrationTest method testReadContainerMetaData.
@Test
void testReadContainerMetaData() {
val interceptor = new MockInterceptor();
val url = "http://example.com/";
interceptor.addRule().get(url).respond(CONTAINER_RESPONSE);
val client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
val uut = new ECSMetaDataReader(url, client, new ObjectMapper());
val result = uut.readContainerMetaData();
assertTrue(result.isPresent());
assertEquals(result.get().getId(), "43481a6ce4842eec8fe72fc28500c6b52edcc0917f105b83379f88cac1ff3946");
}
use of com.opensymphony.xwork2.mock.MockInterceptor in project aws-cloud-meta by prisma-capacity.
the class ECSMetaDataReaderIntegrationTest method testReadTaskMetaData.
@Test
void testReadTaskMetaData() {
val interceptor = new MockInterceptor();
val url = "http://example.com";
interceptor.addRule().get(url + "/task").respond(TASK_RESPONSE);
val client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
val uut = new ECSMetaDataReader(url, client, new ObjectMapper());
val result = uut.readTaskMetaData();
assertTrue(result.isPresent());
assertEquals(result.get().getCluster(), "default");
}
Aggregations