public void testActionsPickedUpFromSuperclass() { allowing_specificationLoader_loadSpecification_any_willReturn(voidSpec); class Customer { @SuppressWarnings("unused") public void someAction(final int x, final long y) { } } class CustomerEx extends Customer { } final Method actionMethod = findMethod(CustomerEx.class, "someAction", new Class[] { int.class, long.class }); final FacetedMethod facetHolderWithParms = FacetedMethod.createForAction(CustomerEx.class, actionMethod, mockSpecificationLoader); facetFactory.processInvocation(new ProcessMethodContext(CustomerEx.class, null, null, actionMethod, methodRemover, facetHolderWithParms)); final Facet facet0 = facetHolderWithParms.getFacet(ActionInvocationFacet.class); assertNotNull(facet0); }
@Test public void whenContributions() throws Exception { // given @DomainService(nature = NatureOfService.VIEW_CONTRIBUTIONS_ONLY) class CustomerService { public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.VIEW_CONTRIBUTIONS_ONLY) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotInServiceMenuFacet.class); assertThat(facet, is(not(nullValue()))); assertThat(facet instanceof NotInServiceMenuFacetDerivedFromDomainServiceFacet, is(true)); final NotInServiceMenuFacetDerivedFromDomainServiceFacet facetDerivedFromDomainServiceFacet = (NotInServiceMenuFacetDerivedFromDomainServiceFacet) facet; assertThat(facetDerivedFromDomainServiceFacet.getNatureOfService(), equalTo(NatureOfService.VIEW_CONTRIBUTIONS_ONLY)); }
@Test public void whenDomain() throws Exception { // given @DomainService(nature = NatureOfService.DOMAIN) class CustomerService { public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.DOMAIN) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, is(not(nullValue()))); assertThat(facet instanceof NotContributedFacetDerivedFromDomainServiceFacet, is(true)); final NotContributedFacetDerivedFromDomainServiceFacet facetDerivedFromDomainServiceFacet = (NotContributedFacetDerivedFromDomainServiceFacet) facet; assertThat(facetDerivedFromDomainServiceFacet.getNatureOfService(), equalTo(NatureOfService.DOMAIN)); }
@Test public void whenDomain() throws Exception { // given @DomainService(nature = NatureOfService.DOMAIN) class CustomerService { public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.DOMAIN) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotInServiceMenuFacet.class); assertThat(facet, is(not(nullValue()))); assertThat(facet instanceof NotInServiceMenuFacetDerivedFromDomainServiceFacet, is(true)); final NotInServiceMenuFacetDerivedFromDomainServiceFacet facetDerivedFromDomainServiceFacet = (NotInServiceMenuFacetDerivedFromDomainServiceFacet) facet; assertThat(facetDerivedFromDomainServiceFacet.getNatureOfService(), equalTo(NatureOfService.DOMAIN)); }
@Test public void testOnDomainServiceForViewWithAssociation() { // given @DomainService(nature = NatureOfService.VIEW) class CustomerService { @ActionLayout(contributed = Contributed.AS_ASSOCIATION) public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.VIEW) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, CoreMatchers.is(not(nullValue()))); assertThat(facet instanceof NotContributedFacetForActionLayoutAnnotation, CoreMatchers.is(true)); final NotContributedFacetForActionLayoutAnnotation facetImpl = (NotContributedFacetForActionLayoutAnnotation) facet; assertThat(facetImpl.value(), CoreMatchers.equalTo(NotContributed.As.ACTION)); }
@Test public void onDomainServiceForViewContributionsOnly() { // given @DomainService(nature = NatureOfService.VIEW_CONTRIBUTIONS_ONLY) class CustomerService { @ActionLayout(contributed = Contributed.AS_NEITHER) public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.VIEW_CONTRIBUTIONS_ONLY) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, CoreMatchers.is(not(nullValue()))); assertThat(facet instanceof NotContributedFacetForActionLayoutAnnotation, CoreMatchers.is(true)); final NotContributedFacetForActionLayoutAnnotation facetImpl = (NotContributedFacetForActionLayoutAnnotation) facet; assertThat(facetImpl.value(), CoreMatchers.equalTo(NotContributed.As.EITHER)); }
@Test public void onDomainServiceForViewWithAction() { // given @DomainService(nature = NatureOfService.VIEW) class CustomerService { @ActionLayout(contributed = Contributed.AS_ACTION) public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.VIEW) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, CoreMatchers.is(not(nullValue()))); assertThat(facet instanceof NotContributedFacetForActionLayoutAnnotation, CoreMatchers.is(true)); final NotContributedFacetForActionLayoutAnnotation facetImpl = (NotContributedFacetForActionLayoutAnnotation) facet; assertThat(facetImpl.value(), CoreMatchers.equalTo(NotContributed.As.ASSOCIATION)); }
@Test public void whenMenu() throws Exception { // given @DomainService(nature = NatureOfService.VIEW_MENU_ONLY) class CustomerService { public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.VIEW_MENU_ONLY) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, is(not(nullValue()))); assertThat(facet instanceof NotContributedFacetDerivedFromDomainServiceFacet, is(true)); final NotContributedFacetDerivedFromDomainServiceFacet facetDerivedFromDomainServiceFacet = (NotContributedFacetDerivedFromDomainServiceFacet) facet; assertThat(facetDerivedFromDomainServiceFacet.getNatureOfService(), equalTo(NatureOfService.VIEW_MENU_ONLY)); }
public void testInstallsParameterAutoCompleteMethodAndRemovesMethod() { final ActionParameterAutoCompleteFacetViaMethodFactory facetFactory = new ActionParameterAutoCompleteFacetViaMethodFactory(); facetFactory.setServicesInjector(mockServicesInjector); // mockSpecificationLoader.setLoadSpecificationStringReturn(voidSpec); allowing_specificationLoader_loadSpecification_any_willReturn(this.voidSpec); class Customer { @SuppressWarnings("unused") public void someAction(final int x, final long y) { } @SuppressWarnings("unused") public List<Integer> autoComplete0SomeAction(String searchArg) { return Collections.emptyList(); } } final Method actionMethod = findMethod(Customer.class, "someAction", new Class[] { int.class, long.class }); final Method autoComplete0Method = findMethod(Customer.class, "autoComplete0SomeAction", new Class[] {String.class}); final FacetedMethod facetHolderWithParms = FacetedMethod.createForAction(Customer.class, actionMethod, mockSpecificationLoader); facetFactory.process(new ProcessMethodContext(Customer.class, null, null, actionMethod, methodRemover, facetHolderWithParms)); final Facet facet0 = facetHolderWithParms.getParameters().get(0).getFacet(ActionParameterAutoCompleteFacet.class); assertNotNull(facet0); assertTrue(facet0 instanceof ActionParameterAutoCompleteFacetViaMethod); final ActionParameterAutoCompleteFacetViaMethod actionAutoCompleteFacetViaMethod0 = (ActionParameterAutoCompleteFacetViaMethod) facet0; assertEquals(autoComplete0Method, actionAutoCompleteFacetViaMethod0.getMethods().get(0)); assertTrue(methodRemover.getRemovedMethodMethodCalls().contains(autoComplete0Method)); }
@Test public void whenNone() throws Exception { // given class CustomerService { public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(null)); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotInServiceMenuFacet.class); assertThat(facet, is(nullValue())); }
@Test public void whenNone() throws Exception { // given class CustomerService { public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(null)); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, is(nullValue())); }
@Test public void whenView() throws Exception { // given @DomainService(nature = NatureOfService.VIEW) class CustomerService { public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.VIEW) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, is(nullValue())); }
@Test public void whenContributions() throws Exception { // given @DomainService(nature = NatureOfService.VIEW_CONTRIBUTIONS_ONLY) class CustomerService { public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.VIEW_CONTRIBUTIONS_ONLY) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, is(nullValue())); }
@Test public void onDomainServiceForViewWithDefault() { // given @DomainService(nature = NatureOfService.VIEW) class CustomerService { @ActionLayout() public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.VIEW) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, CoreMatchers.is(nullValue())); }
@Test public void onDomainServiceForViewWithBoth() { // given @DomainService(nature = NatureOfService.VIEW) class CustomerService { @ActionLayout(contributed = Contributed.AS_BOTH) public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.VIEW) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, CoreMatchers.is(nullValue())); }
@Test public void whenView() throws Exception { // given @DomainService(nature = NatureOfService.VIEW) class CustomerService { public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.VIEW) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotInServiceMenuFacet.class); assertThat(facet, is(nullValue())); }
@Test public void whenMenu() throws Exception { // given @DomainService(nature = NatureOfService.VIEW_MENU_ONLY) class CustomerService { public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.VIEW_MENU_ONLY) { })); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotInServiceMenuFacet.class); assertThat(facet, is(nullValue())); }
@Test public void onDomainServiceForViewMenuOnly() { // given @DomainService(nature = NatureOfService.VIEW_MENU_ONLY) class CustomerService { @ActionLayout(contributed = Contributed.AS_NEITHER) public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.VIEW_MENU_ONLY) { })); allowing(mockObjSpec).getFacet(MixinFacet.class); will(returnValue(null)); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, CoreMatchers.is(nullValue())); }
@Test public void onDomainObjectIsIgnored() { // given @DomainObject class Customer { @ActionLayout(contributed = Contributed.AS_NEITHER) public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(Customer.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(null)); allowing(mockObjSpec).getFacet(MixinFacet.class); will(returnValue(null)); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(Customer.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(Customer.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, CoreMatchers.is(nullValue())); }
@Test public void onDomainServiceForDomainWithBoth() { // given @DomainService(nature = NatureOfService.DOMAIN) class CustomerService { @ActionLayout(contributed = Contributed.AS_NEITHER) public String name() { return "Joe"; } } context.checking(new Expectations() {{ allowing(mockSpecificationLoader).loadSpecification(CustomerService.class); will(returnValue(mockObjSpec)); allowing(mockObjSpec).getFacet(DomainServiceFacet.class); will(returnValue(new DomainServiceFacetAbstract(mockObjSpec, null, NatureOfService.DOMAIN) { })); allowing(mockObjSpec).getFacet(MixinFacet.class); will(returnValue(null)); }}); expectNoMethodsRemoved(); facetedMethod = FacetedMethod.createForAction(CustomerService.class, "name", mockSpecificationLoader); // when facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); // then final Facet facet = facetedMethod.getFacet(NotContributedFacet.class); assertThat(facet, CoreMatchers.is(nullValue())); }