blob: bea992058fca8c375a1c2b47bdc6859a84511315 [file] [log] [blame]
/* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pluto.container.bean.processor.tests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
import javax.inject.Inject;
import javax.xml.namespace.QName;
import org.apache.pluto.container.bean.processor.AnnotatedConfigBean;
import org.apache.pluto.container.bean.processor.AnnotatedMethodStore;
import org.apache.pluto.container.bean.processor.ConfigSummary;
import org.apache.pluto.container.bean.processor.PortletCDIExtension;
import org.apache.pluto.container.bean.processor.PortletInvoker;
import org.apache.pluto.container.bean.processor.fixtures.InvocationResults;
import org.apache.pluto.container.bean.processor.fixtures.event.Event1;
import org.apache.pluto.container.bean.processor.fixtures.event.Event2;
import org.apache.pluto.container.bean.processor.fixtures.mocks.MockEventRequest;
import org.apache.pluto.container.bean.processor.fixtures.mocks.MockEventResponse;
import org.jglue.cdiunit.AdditionalClasses;
import org.jglue.cdiunit.AdditionalPackages;
import org.jglue.cdiunit.CdiRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test class for invoking the annotated event methods.
*
* @author Scott Nicklous
*
*/
@RunWith(CdiRunner.class)
@AdditionalClasses(PortletCDIExtension.class)
@AdditionalPackages(Event1.class)
public class InvokeEventTest {
@Inject
private InvocationResults meths;
private static final MockEventRequest req = new MockEventRequest();
private static final MockEventResponse resp = new MockEventResponse();
@Inject
AnnotatedConfigBean acb;
private AnnotatedMethodStore ams = null;
private ConfigSummary summary = null;
private static String DEFAULT_NS = "http://www.java.net/";
@Before
public void setUp() {
assertNotNull(acb);
ams = acb.getMethodStore();
summary = acb.getSummary();
assertNotNull(ams);
assertNotNull(summary);
ams.setDefaultNamespace(DEFAULT_NS);
}
@Test
public void invoke1() throws Exception {
meths.reset();
PortletInvoker i = new PortletInvoker(acb, "portlet1");
QName qn = new QName("http://www.apache.org", "proc1");
req.setQn(qn);
i.processEvent(req, resp);
List<String> names = meths.getMethods();
assertNotNull(names);
assertEquals(1, names.size());
assertTrue(names.contains(Event1.class.getSimpleName() + "#event1"));
}
@Test
public void invoke2() throws Exception {
meths.reset();
PortletInvoker i = new PortletInvoker(acb, "portlet2");
QName qn = new QName("http://www.apache.org", "proc2");
req.setQn(qn);
i.processEvent(req, resp);
List<String> names = meths.getMethods();
// there are two valid possibilities
List<String> meths = Arrays.asList(new String[] {
Event1.class.getSimpleName() + "#event2",
Event2.class.getSimpleName() + "#event2",
});
assertNotNull(names);
assertEquals(1, names.size());
assertTrue(meths.contains(names.get(0)));
}
@Test
public void invoke3a() throws Exception {
meths.reset();
PortletInvoker i = new PortletInvoker(acb, "portlet3");
QName qn = new QName("http://www.apache.org", "proc3a");
req.setQn(qn);
i.processEvent(req, resp);
List<String> names = meths.getMethods();
assertNotNull(names);
assertEquals(1, names.size());
assertTrue(names.contains(Event2.class.getSimpleName() + "#event1a"));
}
@Test
public void invoke3b() throws Exception {
meths.reset();
PortletInvoker i = new PortletInvoker(acb, "portlet3");
QName qn = new QName(DEFAULT_NS, "proc3b");
req.setQn(qn);
i.processEvent(req, resp);
List<String> names = meths.getMethods();
assertNotNull(names);
assertEquals(1, names.size());
assertTrue(names.contains(Event2.class.getSimpleName() + "#event1b"));
}
@Test
public void invoke3c() throws Exception {
meths.reset();
PortletInvoker i = new PortletInvoker(acb, "portlet3");
QName qn = new QName("http://www.apache.org", "proc3c");
req.setQn(qn);
i.processEvent(req, resp);
List<String> names = meths.getMethods();
assertNotNull(names);
assertEquals(1, names.size());
assertTrue(names.contains(Event2.class.getSimpleName() + "#event1c"));
}
@Test
public void invoke6() throws Exception {
meths.reset();
PortletInvoker i = new PortletInvoker(acb, "portlet6");
QName qn = new QName("http://www.apache.org", "proc6");
req.setQn(qn);
i.processEvent(req, resp);
List<String> names = meths.getMethods();
// there are two valid possibilities
List<String> meths = Arrays.asList(new String[] {
Event2.class.getSimpleName() + "#event6",
Event2.class.getSimpleName() + "#event7",
});
assertNotNull(names);
assertEquals(1, names.size());
assertTrue(meths.contains(names.get(0)));
}
}