Search in sources :

Example 6 with VersionControlGit

use of com.centurylink.mdw.dataaccess.file.VersionControlGit in project mdw-designer by CenturyLinkCloud.

the class AutoTestAntTask method execute.

@Override
public void execute() throws BuildException {
    try {
        if (sslTrustStore != null)
            System.setProperty("javax.net.ssl.trustStore", sslTrustStore.getAbsolutePath());
        DesignerDataAccess.getAuthenticator().authenticate(user, password);
        RestfulServer restfulServer = new RestfulServer(jdbcUrl == null ? "dummy" : jdbcUrl, user, serverUrl.toString());
        if (workflowDir != null) {
            // vcs-based assets
            VersionControl versionControl = new VersionControlGit();
            versionControl.connect(null, null, null, workflowDir);
            restfulServer.setVersionControl(versionControl);
            restfulServer.setRootDirectory(workflowDir);
            restfulServer.setDatabaseUrl("jdbc://dummy");
            designerDataAccess = new DesignerDataAccess(restfulServer, null, user, false);
            designerDataAccess.setCurrentServer(restfulServer);
        } else {
            designerDataAccess = new DesignerDataAccess(restfulServer, null, user, oldNamespaces);
            if (designerDataAccess.getUser(user) == null)
                throw new BuildException("User '" + user + "' not found to run automated tests for this environment.");
            if (!designerDataAccess.getUser(user).hasRole(UserGroupVO.COMMON_GROUP, UserRoleVO.PROCESS_EXECUTION) && !designerDataAccess.getUser(user).hasRole(UserGroupVO.SITE_ADMIN_GROUP, UserRoleVO.PROCESS_EXECUTION))
                throw new BuildException("User '" + user + "' not authorized to run automated tests for this environment.");
        }
        VariableTypeCache.loadCache(designerDataAccess.getVariableTypes());
        log("Setup completed for test suite: '" + suiteName + "'", Project.MSG_ERR);
        try {
            if (stubbing) {
                Stubber stubber = new Stubber() {

                    public String processMessage(String masterRequestId, String request) {
                        try {
                            TestCaseRun run = masterRequestRunMap.get(masterRequestId);
                            if (run == null) {
                                JSONObject requestJson = null;
                                // mdw6
                                ActivityStubRequest activityStubRequest = null;
                                ActivityRuntimeContext activityRuntimeContext = null;
                                // mdw6
                                AdapterStubRequest adapterStubRequest = null;
                                if (request != null && request.trim().startsWith("{")) {
                                    try {
                                        requestJson = new JSONObject(request);
                                    } catch (JSONException ex) {
                                    // unparseable -- handle old way for
                                    // adapter stubbing
                                    }
                                    if (requestJson != null) {
                                        if (requestJson.has(ActivityStubRequest.JSON_NAME)) {
                                            activityStubRequest = new ActivityStubRequest(requestJson);
                                            activityRuntimeContext = activityStubRequest.getRuntimeContext();
                                        } else if (requestJson.has("ActivityRuntimeContext")) {
                                            activityRuntimeContext = new ActivityRuntimeContext(requestJson);
                                        } else if (requestJson.has(AdapterStubRequest.JSON_NAME)) {
                                            adapterStubRequest = new AdapterStubRequest(requestJson);
                                        }
                                    }
                                }
                                if (activityRuntimeContext != null) {
                                    if (activityStubRequest != null) {
                                        // mdw6+
                                        ActivityStubResponse activityStubResponse = new ActivityStubResponse();
                                        activityStubResponse.setPassthrough(true);
                                        return activityStubResponse.getJson().toString(2);
                                    } else {
                                        return "(EXECUTE_ACTIVITY)";
                                    }
                                } else {
                                    if (adapterStubRequest != null) {
                                        // mdw6+
                                        AdapterStubResponse stubResponse = new AdapterStubResponse(AdapterActivity.MAKE_ACTUAL_CALL);
                                        stubResponse.setPassthrough(true);
                                        return stubResponse.getJson().toString(2);
                                    } else {
                                        return AdapterActivity.MAKE_ACTUAL_CALL;
                                    }
                                }
                            }
                            return run.getStubResponse(masterRequestId, request, run.getRunNumber());
                        } catch (Exception ex) {
                            log(ex.getMessage(), ex, Project.MSG_ERR);
                            return null;
                        }
                    }
                };
                if (StubServer.isRunning())
                    StubServer.stop();
                StubServer.start(restfulServer, stubPort, stubber, this.oldNamespaces);
            }
            runTests();
        } finally {
            // try not to leave the socket connection open
            StubServer.stop();
        }
    } catch (BuildException ex) {
        throw ex;
    } catch (Exception ex) {
        try {
            updateResults(true);
        } catch (BuildException bex) {
            throw bex;
        } catch (IOException ioex) {
            log(ioex.getMessage(), ioex, Project.MSG_ERR);
        }
        log(ex.getMessage(), ex, Project.MSG_ERR);
        throw new BuildException(ex);
    }
}
Also used : VersionControlGit(com.centurylink.mdw.dataaccess.file.VersionControlGit) ActivityStubResponse(com.centurylink.mdw.model.value.activity.ActivityStubResponse) JSONException(org.json.JSONException) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) ActivityStubRequest(com.centurylink.mdw.model.value.activity.ActivityStubRequest) IOException(java.io.IOException) VersionControl(com.centurylink.mdw.dataaccess.VersionControl) JSONException(org.json.JSONException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) ActivityRuntimeContext(com.centurylink.mdw.model.value.activity.ActivityRuntimeContext) AdapterStubRequest(com.centurylink.mdw.model.value.event.AdapterStubRequest) JSONObject(org.json.JSONObject) Stubber(com.centurylink.mdw.designer.testing.StubServer.Stubber) DesignerDataAccess(com.centurylink.mdw.designer.DesignerDataAccess) BuildException(org.apache.tools.ant.BuildException) AdapterStubResponse(com.centurylink.mdw.model.value.event.AdapterStubResponse)

Aggregations

VersionControlGit (com.centurylink.mdw.dataaccess.file.VersionControlGit)6 VersionControl (com.centurylink.mdw.dataaccess.VersionControl)5 RestfulServer (com.centurylink.mdw.designer.utils.RestfulServer)4 File (java.io.File)4 IOException (java.io.IOException)4 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)3 RemoteException (java.rmi.RemoteException)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)2 VcsRepository (com.centurylink.mdw.plugin.project.model.VcsRepository)2 URL (java.net.URL)2 XmlException (org.apache.xmlbeans.XmlException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)1 TranslationException (com.centurylink.mdw.common.exception.TranslationException)1 HttpHelper (com.centurylink.mdw.common.utilities.HttpHelper)1 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)1 ProcessImporter (com.centurylink.mdw.dataaccess.ProcessImporter)1 VersionControlDummy (com.centurylink.mdw.dataaccess.VersionControlDummy)1