@Test public void testDeployProcess() throws PluginException { HashSet<RequestParameterType<?>> mandatoryProperties = new HashSet<>(); RequestParameterType<String> prop = new RequestParameterType<>("test", "test"); mandatoryProperties.add(prop); CanonicalProcessType cpf = new CanonicalProcessType(); AnnotationsType anf = new AnnotationsType(); expect(mockDeploymentPlugin.getNativeType()).andReturn("test"); expect(mockDeploymentPlugin.getName()).andReturn("test"); expect(mockDeploymentPlugin.getVersion()).andReturn("1.0"); PluginResultImpl result = new PluginResultImpl(); result.addPluginMessage("test"); expect( mockDeploymentPlugin.deployProcess( EasyMock.eq(cpf), EasyMock.eq(anf), EasyMock.anyObject(PluginRequest.class))) .andReturn(result); replay(mockDeploymentPlugin); List<PluginMessage> messages = myService.deployProcess("test", cpf, anf, mandatoryProperties); assertTrue(messages.size() == 1); verify(mockDeploymentPlugin); }
private void convertToPluginMessage( final PluginResultImpl pluginResult, final Node errorMessage) { if (errorMessage.getChildNodes().getLength() > 1) { pluginResult.addPluginMessage( "{0}: {1}", errorMessage.getFirstChild().getTextContent(), errorMessage.getLastChild().getTextContent()); } else { pluginResult.addPluginMessage("Error: {0}", errorMessage.getFirstChild().getTextContent()); } }
/* * (non-Javadoc) * * @see org.apromore.plugin.deployment.DeploymentPlugin#deployProcess(org.apromore.cpf.CanonicalProcessType, org.apromore.anf.AnnotationsType) */ @Override public PluginResult deployProcess( final CanonicalProcessType canonicalProcess, final AnnotationsType annotation, final PluginRequest request) throws DeploymentException, PluginPropertyNotFoundException { ParameterType<String> userEngineUrl = request.getRequestParameter(yawlEngineUrl); ParameterType<String> userUsername = request.getRequestParameter(yawlEngineUsername); ParameterType<String> userPassword = request.getRequestParameter(yawlEnginePassword); ParameterType<Boolean> doAutoLaunch = request.getRequestParameter(autoLaunch); checkProperties(userEngineUrl); PluginResultImpl pluginResult = newPluginResult(); YAWLEngineClient yawlEngineClient = engineClientFactory.newInstance( userEngineUrl.getValue(), userUsername.getValue(), userPassword.getValue()); Node connectResponse = yawlEngineClient.connectToYAWL(); if (connectResponse.getNodeName().equals("failure")) { throw new DeploymentException( "Could not connect to YAWL engine. Reason: " + connectResponse.getTextContent()); } else { try { String sessionHandle = connectResponse.getTextContent(); if (sessionHandle != null) { String yawlSpec = deCanoniseYAWL(canonicalProcess, annotation); Node uploadResponse = yawlEngineClient.uploadYAWLSpecification(yawlSpec, sessionHandle); if (uploadResponse.getNodeName().equals("failure")) { pluginResult.addPluginMessage( "Failure deploying process {0}", canonicalProcess.getName()); if (uploadResponse.getChildNodes().getLength() > 0) { Node reasonNode = uploadResponse.getChildNodes().item(0); for (int i = 0; i < reasonNode.getChildNodes().getLength(); i++) { convertToPluginMessage(pluginResult, reasonNode.getChildNodes().item(i)); } } } else { if (uploadResponse.getTextContent().isEmpty()) { pluginResult.addPluginMessage( "Process {0} successfully deployed.", canonicalProcess.getName(), uploadResponse.getTextContent()); if (doAutoLaunch.getValue()) { doAutoLaunch(); } } else { pluginResult.addPluginMessage( "YAWL Engine message: {0}", uploadResponse.getTextContent()); } } } else { throw new DeploymentException( "Could not connect to YAWL engine. Invalid Session Handle returned!"); } } catch (CanoniserException e) { throw new DeploymentException("Could not deCanonise to YAWL", e); } } return pluginResult; }