Skip to content

Commit

Permalink
Merge pull request wildfly-extras#63 from jtymel/elytron
Browse files Browse the repository at this point in the history
Do not leave mess after AddCredentialStoreAliasOnlineTest is run
  • Loading branch information
jtymel authored Jan 31, 2017
2 parents f4cd22d + 4d67692 commit c7f938f
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
import org.jboss.arquillian.junit.Arquillian;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.wildfly.extras.creaper.commands.elytron.AbstractElytronOnlineTest;
import org.wildfly.extras.creaper.commands.elytron.CredentialRef;
import org.wildfly.extras.creaper.core.CommandFailedException;
import org.wildfly.extras.creaper.core.online.OnlineCommand;
import org.wildfly.extras.creaper.core.online.OnlineCommandContext;
import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
import org.wildfly.extras.creaper.core.online.operations.Address;
import org.wildfly.extras.creaper.core.online.operations.Operations;
import org.wildfly.extras.creaper.core.online.operations.Values;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand All @@ -28,13 +36,25 @@ public class AddCredentialStoreAliasOnlineTest extends AbstractElytronOnlineTest
private static final Address TEST_CREDENTIAL_STORE_ALIAS_ADDRESS2 = TEST_CREDENTIAL_STORE_ADDRESS
.and("alias", TEST_CREDENTIAL_STORE_ALIAS_NAME2);

@ClassRule
public static TemporaryFolder tmp = new TemporaryFolder();

@BeforeClass
public static void createTmpPath() throws Exception {
try (OnlineManagementClient client = createManagementClient()) {
AddTmpDirectoryToPath addTargetToPath = new AddTmpDirectoryToPath();
client.apply(addTargetToPath);
}
}

@Before
public void createCredentialStore() throws Exception {
AddCredentialStore addCredentialStore = new AddCredentialStore.Builder(TEST_CREDENTIAL_STORE_NAME)
.uri("cr-store://test.testCs")
.credentialReference(new CredentialRef.CredentialRefBuilder()
.clearText("somePassword")
.build())
.relativeTo("tmp")
.build();

client.apply(addCredentialStore);
Expand Down Expand Up @@ -197,4 +217,18 @@ public void addCredentialStoreAlias_emptySecretValue() throws Exception {

fail("Creating command with empty secret-value should throw exception");
}

private static final class AddTmpDirectoryToPath implements OnlineCommand {

@Override
public void apply(OnlineCommandContext ctx) throws Exception {
Operations ops = new Operations(ctx.client);
Address pathAddress = Address.root()
.and("path", "tmp");

ops.add(pathAddress, Values.empty()
.and("path", tmp.getRoot().getAbsolutePath()));
}
}

}

0 comments on commit c7f938f

Please sign in to comment.