TemplateGenerator { public Template generate() { Template result = new Template(); result.setTemplateId(UUID.randomUUID().toString()); Context context = buildContext(contextInfo); result.setContext(context); Terms terms = new Terms(); AllTerms allTerms = new AllTerms(); result.setTerms(terms); terms.setAllTerms(allTerms); ServiceDescriptionTerm sdt = new ServiceDescriptionTerm(); allTerms.setServiceDescriptionTerm(sdt); List<ServiceProperties> serviceProperties = new ArrayList<>(); allTerms.setServiceProperties(serviceProperties); List<GuaranteeTerm> gts = new ArrayList<>(); allTerms.setGuaranteeTerms(gts); for (String moduleName : this.rules.keySet()) { MonitoringRules rules = this.rules.get(moduleName); for (MonitoringRule rule : rules.getMonitoringRules()) { GuaranteeTerm gt = generateGuaranteeTerm(rule); if (gt != NULL_GUARANTEE_TERM) { gts.add(gt); } } } return result; } TemplateGenerator(SlaInfo slaInfo); Template generate();  }
@Test public void testGenerate() throws JAXBException { ContextInfo context = new ContextInfo("provider", "consumer", "service", new Validity(2, 0, 0)); MonitoringRules rules = JaxbUtils.load( MonitoringRules.class, this.getClass().getResourceAsStream("/seacloudsRules.xml")); SlaInfo slaInfo = new SlaInfo(context, Collections.singletonMap("frontend", rules)); TemplateGenerator g = new TemplateGenerator(slaInfo); Template t = g.generate(); JaxbUtils.print(t); assertEquals(context.getProvider(), t.getContext().getAgreementResponder()); assertEquals(context.getConsumer(), t.getContext().getAgreementInitiator()); assertEquals(context.getService(), t.getContext().getService()); assertEquals(2, t.getTerms().getAllTerms().getGuaranteeTerms().size()); List<GuaranteeTerm> expectedGts = new ArrayList<GuaranteeTerm>(); expectedGts.add(newGuaranteeTerm( "tomcat_server", "tomcat_server/AvarageResponseTimeInternalComponent", "AvarageResponseTime_tomcat_server_Violation NOT_EXISTS")); expectedGts.add(newGuaranteeTerm( "tomcat_server", "tomcat_server/AppAvailable", "AvarageAppAvailability_tomcat_server_Violation NOT_EXISTS")); List<GuaranteeTerm> actualGts = t.getTerms().getAllTerms().getGuaranteeTerms(); for (int i = 0; i < actualGts.size(); i++) { GuaranteeTerm expected = expectedGts.get(i); GuaranteeTerm actual = expectedGts.get(i); checkGuaranteeTerm(expected, actual); } }