S++Core systems, human-reviewable
SDK DOCUMENTATION ยท 1.0-SNAPSHOTStart the tutorial

CustomServiceTest.java

sdk-tools/samples/custom-services/src/test/java/example/technical/CustomServiceTest.java

1package example.technical;23import example.generated.ledger.model.Facts;4import example.generated.ledger.service.SimplePreview;5import example.generated.ledger.service.SimpleTwice;6import com.servpp.service.server.DefaultServiceContainer;7import com.servpp.service.technical.ServiceInterceptors;8import com.servpp.service.technical.TechnicalInvocation.Phase;9import org.junit.Test;10import static org.junit.Assert.*;1112public class CustomServiceTest {13    @Test public void generatedScenarioUsesOnlyExplicitCustomBindings()throws Exception {14        var container=DefaultServiceContainer.getInstance();container.clear();CallCounter.reset();15        try {16            try{Class.forName("com.servpp.service.runtime.OfficialPropertyChanges");fail("Commercial implementation installed");}17            catch(ClassNotFoundException expected){}18            container.registerService("ledger.twice",ServiceInterceptors.decorate(new SimpleTwice()));19            var facts=new Facts().amount(7);20            var scenario = ServiceInterceptors.decorate(new SimplePreview());21            var request = new example.generated.ledger.model.PreviewRequest().facts(facts);22            com.servpp.service.runtime.RemoteServiceIngress.execute(scenario, request, "fixture", "preview");23            assertEquals(Integer.valueOf(14),facts.getAmount());24            assertEquals(1,CallCounter.count("ledger.preview",Phase.BEFORE));25            assertEquals(1,CallCounter.count("ledger.preview",Phase.AFTER));26            assertEquals(1,CallCounter.count("ledger.twice",Phase.BEFORE));27            assertEquals(1,CallCounter.count("ledger.twice",Phase.AFTER));28            assertEquals(0,CallCounter.count("ledger.preview",Phase.FAILURE));29        } finally {container.clear();CallCounter.reset();}30    }31}