Ejemplo n.º 1
0
func TestNewAppCreation(t *testing.T) {
	t.Log("Testing creation of AppCreation object")
	url := urls.GetUrls()
	appCreation := command.NewAppCreation(url.CreateApp)

	if(appCreation.Url != url.CreateApp) {
		t.Errorf("Expected '%s', but it was '%s' instead.", url.CreateApp, appCreation.Url)
	}
}
Ejemplo n.º 2
0
func TestMetadata(t *testing.T){
	t.Log("Testing metadata")
	url := urls.GetUrls()
	appCreation := command.NewAppCreation(url.CreateApp)
	metadata := appCreation.Metadata()

	if(metadata.Name != "createNewApplication") {
		t.Errorf("Expected 'createNewApplication', but it was '%s' instead.", metadata.Name)
	}
}
Ejemplo n.º 3
0
/* NewFactory returns a new concreteFactory with with a map of commands.*/
func NewFactory() (factory CommandFactory) {
	//Get Urls
	urls := urls.GetUrls()
	//Create map of commands
	factory.CmdsByName = make(map[string]Command)
	factory.CmdsByName["login"] = NewLogin(urls.Login)
	factory.CmdsByName["getApplicationsOfUser"] = NewAppList(urls.ListApps)
	factory.CmdsByName["getAppVersionsInStage"] = NewVersionsList(urls.ListVersions)
	factory.CmdsByName["createNewApplication"] = NewAppCreation(urls.CreateApp)
	factory.CmdsByName["getAppInfo"] = NewAppInfo(urls.GetAppInfo)
	factory.CmdsByName["createArtifact"] = NewArtifact(urls.CreateArtifact)
	factory.CmdsByName["getBuildAndDeployStatusForVersion"] = NewBuildSuccessInfo(urls.GetBuildSuccessInfo)
	factory.CmdsByName["printBuildLogs"] = NewPrintLogs(urls.PrintLogs)
	factory.CmdsByName["triggerBuild"] = NewBuildApp(urls.CreateArtifact)
	factory.CmdsByName["logout"] = NewLogout(urls.Logout)
	factory.CmdsByName["deleteApplication"] = NewAppDeletion(urls.DeleteApp)
	return
}
Ejemplo n.º 4
0
func TestRun(t *testing.T){
	t.Log("Testing metadata")
	url := urls.GetUrls()
	appCreation := command.NewAppCreation(url.CreateApp)

	configs := command.CommandConfigs{
		Url : "https://apps.cloud.wso2.com/appmgt/site/blocks/application/add/ajax/add.jag",
		Query : "action=createNewApplication&userName=dilhasha.uom.gmail.com@uomcse&applicationKey=de&applicationName=De&applicationDescription=sh&applicationType=war&repositoryType=git",
		Cookie : "JSESSIONID=11450C5F38F9F167D55FF2F268436068",
	}

	success,cookie := appCreation.Run(configs)

	if(cookie != configs.Cookie) {
		t.Errorf("Expected '%s', but it was '%s' instead.", configs.Cookie , cookie)
	}
	if(success == false){
		t.Errorf("Run command failed for appCreation. Check cookie and whether app already exists.")
	}
}
Ejemplo n.º 5
0
/* Run calls the Run function of CommandConfigs and verifies the response from that call.*/
func (buildApp BuildApp) Run(configs CommandConfigs) (bool, string) {

	//Construct query for creating an artifact
	query := configs.Query
	query = strings.Replace(query, "triggerBuild", "createArtifact", 1)
	configs.Query = query

	response := configs.Run()
	//if request did not fail
	if response != nil {
		defer response.Body.Close()
	} else {
		//exit the cli
		return true, ""
	}
	body, _ := ioutil.ReadAll(response.Body)

	bodyStr := string(body)
	var errorFormat formats.ErrorFormat

	err := json.Unmarshal([]byte(bodyStr), &errorFormat)

	//waitFlag := false
	if err == nil {
		if errorFormat.ErrorCode == http.StatusUnauthorized {
			fmt.Println("Your session has expired. Please login and try again!")
			return false, configs.Cookie
		}
	}
	//Ask whether user wants to wait
	fmt.Println("Build has been triggered...")
	fmt.Println("Do you want to wait until build success? ( Y - Yes , N - No )")
	fmt.Scanf("%s", &bodyStr)
	//User chooses to wait
	if bodyStr == "Y" || bodyStr == "YES" {
		fmt.Println("waiting...")
		//Construct query for getting last build success id
		query := configs.Query
		query = strings.Replace(query, "createArtifact", "getBuildAndDeployStatusForVersion", 1)
		configs.Query = query
		configs.Url = urls.GetUrls().GetBuildSuccessInfo
		continueFlag, buildId := checkBuildId(configs)
		id := buildId
		//If the build has not finished yet
		for continueFlag {
			continueFlag, buildId = checkBuildId(configs)
			if buildId != id {
				//New build is successful
				break
			}
		}
		if buildId == id+1 {
			//Build is successful
			fmt.Println("\nThe build has been successful. Displaying build logs below..\n")
			query := configs.Query
			query = strings.Replace(query, "getBuildAndDeployStatusForVersion", "printBuildLogs", 1)
			query = strings.Replace(query, "version", "applicationVersion", 1)

			//append build id and tenant domain
			query = query + "&lastBuildId=" + strconv.FormatInt(buildId, 10) + "&tenantDomain=" + getTenantDomain()
			configs.Query = query
			configs.Url = urls.GetUrls().PrintLogs
			printLogs := NewPrintLogs(urls.GetUrls().PrintLogs)
			return printLogs.Run(configs)

		} else if !continueFlag { //Error occurred while performing request
			return false, configs.Cookie
		}

	}
	return true, configs.Cookie
}