@Test public void testWrongStateDoesNothing() throws Exception { DeploymentDAO deploymentDAO = mock(DeploymentDAO.class); DeploymentEventService deploymentEventService = mock(DeploymentEventService.class); AcceptAgreementEventHandler acceptAgreementEvent = new AcceptAgreementEventHandler(); acceptAgreementEvent.deploymentDAO = deploymentDAO; acceptAgreementEvent.deploymentEventService = deploymentEventService; DeploymentEvent deploymentEvent = new DeploymentEvent(); deploymentEvent.setDeploymentId(22); deploymentEvent.setDeploymentStatus("1111"); Deployment deployment = new Deployment(); deployment.setId(22); deployment.setStatus("UNKNOWN"); when(deploymentDAO.getById(22)).thenReturn(deployment); acceptAgreementEvent.acceptAgreement(Event.wrap(deploymentEvent)); verify(deploymentDAO, times(1)).getById(deploymentEvent.getDeploymentId()); verify(deploymentDAO, never()).update(any(Deployment.class)); verify(deploymentEventService, never()).fireDeploymentEvent(any(DeploymentEvent.class)); }
@Selector(value="topic.deployment.status", reactor="@rootReactor") public void acceptAgreement(Event<DeploymentEvent> event) throws Exception { DeploymentEvent deploymentEvent = event.getData(); logger.info("Deployment " + deploymentEvent.getDeploymentId() + " NEGOTIATED, checking if it automatica agreement"); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); PriceModellerClient.getInstance().initializeApplication(deploymentEvent.getApplicationName(), deploymentEvent.getDeploymentId(), deployment.getSchema()); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_NEGOTIATIED) && deploymentEvent.isAutomaticNegotiation() == true) { logger.info(" Moving deployment id: " + deploymentEvent.getDeploymentId() + " to " + Dictionary.APPLICATION_STATUS_NEGOTIATIED + " state"); if(Configuration.enableSLAM.equals("yes")) { List<Agreement> agreements = deploymentDAO.getById(deploymentEvent.getDeploymentId()).getAgreements(); for(Agreement agreement: agreements) { if(agreement.getOrderInArray() == 0) { SLASOITemplateParser parser = new SLASOITemplateParser(); SLATemplate slat = parser.parseTemplate(agreement.getSlaAgreement()); NegotiationWsClient client = new NegotiationWsClient(); SlaTranslator slaTranslator = new SlaTranslatorImplNoOsgi(); client.setSlaTranslator(slaTranslator); logger.debug("Sending create agreement SOAP request..."); SLA slaAgreement = client.createAgreement(Configuration.slamURL, slat, agreement.getNegotiationId()); logger.info("SLA:"); logger.info(slaAgreement); agreement.setAccepted(true); deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); deployment.setSlaUUID(slaAgreement.getUuid()); deploymentDAO.update(deployment); agreementDAO.update(agreement); finalization(deployment, deploymentEvent); } } } else { finalization(deployment, deploymentEvent); } } }
AcceptAgreementEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void acceptAgreement(Event<DeploymentEvent> event) throws Exception { DeploymentEvent deploymentEvent = event.getData(); logger.info("Deployment " + deploymentEvent.getDeploymentId() + " NEGOTIATED, checking if it automatica agreement"); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); PriceModellerClient.getInstance().initializeApplication(deploymentEvent.getApplicationName(), deploymentEvent.getDeploymentId(), deployment.getSchema()); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_NEGOTIATIED) && deploymentEvent.isAutomaticNegotiation() == true) { logger.info(" Moving deployment id: " + deploymentEvent.getDeploymentId() + " to " + Dictionary.APPLICATION_STATUS_NEGOTIATIED + " state"); if(Configuration.enableSLAM.equals("yes")) { List<Agreement> agreements = deploymentDAO.getById(deploymentEvent.getDeploymentId()).getAgreements(); for(Agreement agreement: agreements) { if(agreement.getOrderInArray() == 0) { SLASOITemplateParser parser = new SLASOITemplateParser(); SLATemplate slat = parser.parseTemplate(agreement.getSlaAgreement()); NegotiationWsClient client = new NegotiationWsClient(); SlaTranslator slaTranslator = new SlaTranslatorImplNoOsgi(); client.setSlaTranslator(slaTranslator); logger.debug("Sending create agreement SOAP request..."); SLA slaAgreement = client.createAgreement(Configuration.slamURL, slat, agreement.getNegotiationId()); logger.info("SLA:"); logger.info(slaAgreement); agreement.setAccepted(true); deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); deployment.setSlaUUID(slaAgreement.getUuid()); deploymentDAO.update(deployment); agreementDAO.update(agreement); finalization(deployment, deploymentEvent); } } } else { finalization(deployment, deploymentEvent); } } } }
AcceptAgreementEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void acceptAgreement(Event<DeploymentEvent> event) throws Exception { DeploymentEvent deploymentEvent = event.getData(); logger.info("Deployment " + deploymentEvent.getDeploymentId() + " NEGOTIATED, checking if it automatica agreement"); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); PriceModellerClient.getInstance().initializeApplication(deploymentEvent.getApplicationName(), deploymentEvent.getDeploymentId(), deployment.getSchema()); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_NEGOTIATIED) && deploymentEvent.isAutomaticNegotiation() == true) { logger.info(" Moving deployment id: " + deploymentEvent.getDeploymentId() + " to " + Dictionary.APPLICATION_STATUS_NEGOTIATIED + " state"); if(Configuration.enableSLAM.equals("yes")) { List<Agreement> agreements = deploymentDAO.getById(deploymentEvent.getDeploymentId()).getAgreements(); for(Agreement agreement: agreements) { if(agreement.getOrderInArray() == 0) { SLASOITemplateParser parser = new SLASOITemplateParser(); SLATemplate slat = parser.parseTemplate(agreement.getSlaAgreement()); NegotiationWsClient client = new NegotiationWsClient(); SlaTranslator slaTranslator = new SlaTranslatorImplNoOsgi(); client.setSlaTranslator(slaTranslator); logger.debug("Sending create agreement SOAP request..."); SLA slaAgreement = client.createAgreement(Configuration.slamURL, slat, agreement.getNegotiationId()); logger.info("SLA:"); logger.info(slaAgreement); agreement.setAccepted(true); deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); deployment.setSlaUUID(slaAgreement.getUuid()); deploymentDAO.update(deployment); agreementDAO.update(agreement); finalization(deployment, deploymentEvent); } } } else { finalization(deployment, deploymentEvent); } } }  }
AcceptAgreementEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void acceptAgreement(Event<DeploymentEvent> event) throws Exception { DeploymentEvent deploymentEvent = event.getData(); logger.info("Deployment " + deploymentEvent.getDeploymentId() + " NEGOTIATED, checking if it automatica agreement"); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); PriceModellerClient.getInstance().initializeApplication(deploymentEvent.getApplicationName(), deploymentEvent.getDeploymentId(), deployment.getSchema()); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_NEGOTIATIED) && deploymentEvent.isAutomaticNegotiation() == true) { logger.info(" Moving deployment id: " + deploymentEvent.getDeploymentId() + " to " + Dictionary.APPLICATION_STATUS_NEGOTIATIED + " state"); if(Configuration.enableSLAM.equals("yes")) { List<Agreement> agreements = deploymentDAO.getById(deploymentEvent.getDeploymentId()).getAgreements(); for(Agreement agreement: agreements) { if(agreement.getOrderInArray() == 0) { SLASOITemplateParser parser = new SLASOITemplateParser(); SLATemplate slat = parser.parseTemplate(agreement.getSlaAgreement()); NegotiationWsClient client = new NegotiationWsClient(); SlaTranslator slaTranslator = new SlaTranslatorImplNoOsgi(); client.setSlaTranslator(slaTranslator); logger.debug("Sending create agreement SOAP request..."); SLA slaAgreement = client.createAgreement(Configuration.slamURL, slat, agreement.getNegotiationId()); logger.info("SLA:"); logger.info(slaAgreement); agreement.setAccepted(true); deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); deployment.setSlaUUID(slaAgreement.getUuid()); deploymentDAO.update(deployment); agreementDAO.update(agreement); finalization(deployment, deploymentEvent); } } } else { finalization(deployment, deploymentEvent); } } }  @Selector(value="topic.deployment.status", reactor="@rootReactor") void acceptAgreement(Event<DeploymentEvent> event); }
AcceptAgreementEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void acceptAgreement(Event<DeploymentEvent> event) throws Exception { DeploymentEvent deploymentEvent = event.getData(); logger.info("Deployment " + deploymentEvent.getDeploymentId() + " NEGOTIATED, checking if it automatica agreement"); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); PriceModellerClient.getInstance().initializeApplication(deploymentEvent.getApplicationName(), deploymentEvent.getDeploymentId(), deployment.getSchema()); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_NEGOTIATIED) && deploymentEvent.isAutomaticNegotiation() == true) { logger.info(" Moving deployment id: " + deploymentEvent.getDeploymentId() + " to " + Dictionary.APPLICATION_STATUS_NEGOTIATIED + " state"); if(Configuration.enableSLAM.equals("yes")) { List<Agreement> agreements = deploymentDAO.getById(deploymentEvent.getDeploymentId()).getAgreements(); for(Agreement agreement: agreements) { if(agreement.getOrderInArray() == 0) { SLASOITemplateParser parser = new SLASOITemplateParser(); SLATemplate slat = parser.parseTemplate(agreement.getSlaAgreement()); NegotiationWsClient client = new NegotiationWsClient(); SlaTranslator slaTranslator = new SlaTranslatorImplNoOsgi(); client.setSlaTranslator(slaTranslator); logger.debug("Sending create agreement SOAP request..."); SLA slaAgreement = client.createAgreement(Configuration.slamURL, slat, agreement.getNegotiationId()); logger.info("SLA:"); logger.info(slaAgreement); agreement.setAccepted(true); deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); deployment.setSlaUUID(slaAgreement.getUuid()); deploymentDAO.update(deployment); agreementDAO.update(agreement); finalization(deployment, deploymentEvent); } } } else { finalization(deployment, deploymentEvent); } } }  @Selector(value="topic.deployment.status", reactor="@rootReactor") void acceptAgreement(Event<DeploymentEvent> event);  }