Skip to content

Commit

Permalink
ftest: Partial lazy initialization of entities
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed Aug 10, 2023
1 parent ee0adcc commit 576e184
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import com.fortify.cli.ftest._common.spec.FcliBaseSpec
import com.fortify.cli.ftest._common.spec.FcliSession
import com.fortify.cli.ftest._common.spec.Prefix
import com.fortify.cli.ftest.ssc._common.SSCAppVersion
import com.fortify.cli.ftest.ssc._common.SSCUser
import com.fortify.cli.ftest.ssc._common.SSCUserSupplier
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Stepwise

@Prefix("ssc.appversion-user") @FcliSession(SSC) @Stepwise
class SSCAppVersionUserSpec extends FcliBaseSpec {
@Shared @AutoCleanup SSCAppVersion version = new SSCAppVersion().create()
@Shared @AutoCleanup SSCUser user = new SSCUser().create()
@Shared @AutoCleanup SSCUserSupplier userSupplier = new SSCUserSupplier()

def "list"() {
def args = "ssc appversion-user list --appversion " + version.appName + ":" + version.versionName
Expand All @@ -30,14 +30,14 @@ class SSCAppVersionUserSpec extends FcliBaseSpec {
}

def "add"() {
def args = "ssc appversion-user add " + user.userName + " --appversion " + version.appName + ":" + version.versionName
def args = "ssc appversion-user add " + userSupplier.user.userName + " --appversion " + version.appName + ":" + version.versionName
when:
def result = Fcli.run(args)
then:
verifyAll(result.stdout) {
size()==2
it[0].replace(" ","").equals("IdEntitynameDisplaynameTypeEmailIsldapAction");
it[1].contains(user.userName)
it[1].contains(userSupplier.user.userName)
}
}

Expand All @@ -49,7 +49,7 @@ class SSCAppVersionUserSpec extends FcliBaseSpec {
verifyAll(result.stdout) {
size()==2
it[0].replace(" ","").equals("IdEntitynameDisplaynameTypeEmailIsldap");
it[1].contains(user.userName)
it[1].contains(userSupplier.user.userName)
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Copyright 2023 Open Text.
*
* The only warranties for products and services of Open Text
* and its affiliates and licensors ("Open Text") are as may
* be set forth in the express warranty statements accompanying
* such products and services. Nothing herein should be construed
* as constituting an additional warranty. Open Text shall not be
* liable for technical or editorial errors or omissions contained
* herein. The information contained herein is subject to change
* without notice.
*/
package com.fortify.cli.ftest.ssc._common

import com.fortify.cli.ftest._common.Fcli

public class SSCUserSupplier implements Closeable, AutoCloseable {
private SSCUser user;

public SSCUser getUser() {
if ( !user ) {
user = new SSCUser().create()
}
return user
}

@Override
public void close() {
if ( user ) {
user.close();
user = null;
}
}

public static class SSCUser {
private final String random = System.currentTimeMillis()
private final String fcliVariableName = "ssc_user_"+random
private final String userName = "fcli-temp-user"+random

public SSCUserSupplier create() {
Fcli.run("ssc user create --username $userName" +
" --password P@ssW._ord123" +
" --firstname fName" +
" --lastname lName" +
" --email [email protected]" +
" --roles admin" +
" --store $fcliVariableName",
{it.expectSuccess(true, "Unable to create user")})
return this
}

public String get(String propertyPath) {
Fcli.run("util var contents $fcliVariableName -o expr={$propertyPath}",
{it.expectSuccess(true, "Error getting application version property "+propertyPath)})
.stdout[0]
}

public String getVariableName() {
return fcliVariableName
}

public String getVariableRef() {
return "::"+fcliVariableName+"::"
}

public void close() {
Fcli.run("ssc user delete ::$fcliVariableName::userName",
{it.expectSuccess(true, "Unable to delete user")})
}
}
}

0 comments on commit 576e184

Please sign in to comment.