NotInServiceMenuFacetDerivedFromDomainServiceFacetFactory extends FacetFactoryAbstract { @Override public void process(final ProcessMethodContext processMethodContext) { final Method method = processMethodContext.getMethod(); final Class<?> declaringClass = method.getDeclaringClass(); final ObjectSpecification spec = getSpecificationLoader().loadSpecification(declaringClass); final DomainServiceFacet domainServiceFacet = spec.getFacet(DomainServiceFacet.class); if(domainServiceFacet == null || domainServiceFacet.isFallback()) { return; } final NatureOfService natureOfService = domainServiceFacet.getNatureOfService(); if(natureOfService.isView()) { return; } final FacetedMethod facetHolder = processMethodContext.getFacetHolder(); FacetUtil.addFacet(new NotInServiceMenuFacetDerivedFromDomainServiceFacet(natureOfService, facetHolder)); } NotInServiceMenuFacetDerivedFromDomainServiceFacetFactory(); @Override void process(final ProcessMethodContext processMethodContext);  }
@Test public void whenDomain() throws Exception { @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"); facetFactory.setMetaModelContext(super.metaModelContext); facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); 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 whenView() throws Exception { @DomainService() 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"); facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); final Facet facet = facetedMethod.getFacet(NotInServiceMenuFacet.class); assertThat(facet, is(nullValue())); }
@Test public void whenMenu() throws Exception { @DomainService() 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"); facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); final Facet facet = facetedMethod.getFacet(NotInServiceMenuFacet.class); assertThat(facet, is(nullValue())); }
@Test public void whenNone() throws Exception { 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"); facetFactory.process(new FacetFactory.ProcessMethodContext(CustomerService.class, null, facetedMethod.getMethod(), mockMethodRemover, facetedMethod)); final Facet facet = facetedMethod.getFacet(NotInServiceMenuFacet.class); assertThat(facet, is(nullValue())); }