Skip to content

Commit

Permalink
Fixed few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bdpiprava committed Nov 21, 2018
1 parent 9f44dbe commit 5859da9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,95 +46,95 @@ public void assertJsonStructure() throws Exception {

assertThat(response.responseCode(), is(200));
String expectedJSON = "{\n" +
" \"go_server_url\": {\n" +
" \"display-name\": \"Go Server URL\",\n" +
" \"private_registry_custom_credentials\": {\n" +
" \"display-name\": \"Private Registry credentials setup\",\n" +
" \"default-value\": \"true\",\n" +
" \"required\": true,\n" +
" \"secure\": false,\n" +
" \"display-order\": \"0\"\n" +
" },\n" +
" \"environment_variables\": {\n" +
" \"display-name\": \"Environment Variables\",\n" +
" \"required\": false,\n" +
" \"secure\": false,\n" +
" \"display-order\": \"1\"\n" +
" \"display-order\": \"10\"\n" +
" },\n" +
" \"max_docker_containers\": {\n" +
" \"display-name\": \"Maximum containers to allow\",\n" +
" \"private_registry_username\": {\n" +
" \"display-name\": \"Private Registry Username\",\n" +
" \"required\": true,\n" +
" \"secure\": false,\n" +
" \"display-order\": \"2\"\n" +
" \"display-order\": \"11\"\n" +
" },\n" +
" \"docker_uri\": {\n" +
" \"display-name\": \"Docker URI\",\n" +
" \"private_registry_server\": {\n" +
" \"display-name\": \"Private Registry Server\",\n" +
" \"required\": true,\n" +
" \"secure\": false,\n" +
" \"display-order\": \"3\"\n" +
" \"display-order\": \"9\"\n" +
" },\n" +
" \"auto_register_timeout\": {\n" +
" \"display-name\": \"Agent auto-register Timeout (in minutes)\",\n" +
" \"default-value\": \"10\",\n" +
" \"go_server_url\": {\n" +
" \"display-name\": \"Go Server URL\",\n" +
" \"required\": true,\n" +
" \"secure\": false,\n" +
" \"display-order\": \"4\"\n" +
" },\n" +
" \"docker_ca_cert\": {\n" +
" \"display-name\": \"Docker CA Certificate\",\n" +
" \"required\": false,\n" +
" \"secure\": true,\n" +
" \"display-order\": \"5\"\n" +
" \"display-order\": \"0\"\n" +
" },\n" +
" \"docker_client_key\": {\n" +
" \"display-name\": \"Docker Client Key\",\n" +
" \"required\": false,\n" +
" \"secure\": true,\n" +
" \"display-order\": \"6\"\n" +
" },\n" +
" \"docker_client_cert\": {\n" +
" \"display-name\": \"Docker Client Certificate\",\n" +
" \"required\": false,\n" +
" \"secure\": true,\n" +
" \"display-order\": \"7\"\n" +
" }," +
" \"enable_private_registry_authentication\": {\n" +
" \"display-name\": \"Use Private Registry\",\n" +
" \"default-value\": \"false\",\n" +
" \"required\": true,\n" +
" \"required\": false,\n" +
" \"secure\": false,\n" +
" \"display-order\": \"8\"\n" +
" }," +
" \"private_registry_server\": {\n" +
" \"display-name\": \"Private Registry Server\",\n" +
" },\n" +
" \"pull_on_container_create\": {\n" +
" \"display-name\": \"Pull image before creating the container\",\n" +
" \"default-value\": \"false\",\n" +
" \"required\": true,\n" +
" \"secure\": false,\n" +
" \"display-order\": \"13\"\n" +
" },\n" +
" \"docker_ca_cert\": {\n" +
" \"display-name\": \"Docker CA Certificate\",\n" +
" \"required\": false,\n" +
" \"secure\": true,\n" +
" \"display-order\": \"5\"\n" +
" },\n" +
" \"environment_variables\": {\n" +
" \"display-name\": \"Environment Variables\",\n" +
" \"required\": false,\n" +
" \"secure\": false,\n" +
" \"display-order\": \"9\"\n" +
" }," +
" \"private_registry_custom_credentials\": {\n" +
" \"display-name\": \"Private Registry credentials setup\",\n" +
" \"default-value\": \"true\",\n" +
" \"display-order\": \"1\"\n" +
" },\n" +
" \"docker_uri\": {\n" +
" \"display-name\": \"Docker URI\",\n" +
" \"required\": true,\n" +
" \"secure\": false,\n" +
" \"display-order\": \"10\"\n" +
" }," +
" \"private_registry_username\": {\n" +
" \"display-name\": \"Private Registry Username\",\n" +
" \"required\": false,\n" +
" \"display-order\": \"3\"\n" +
" },\n" +
" \"max_docker_containers\": {\n" +
" \"display-name\": \"Maximum containers to allow\",\n" +
" \"required\": true,\n" +
" \"secure\": false,\n" +
" \"display-order\": \"11\"\n" +
" }," +
" \"display-order\": \"2\"\n" +
" },\n" +
" \"private_registry_password\": {\n" +
" \"display-name\": \"Private Registry Password\",\n" +
" \"required\": false,\n" +
" \"required\": true,\n" +
" \"secure\": true,\n" +
" \"display-order\": \"12\"\n" +
" }," +
" \"pull_on_container_create\": {\n" +
" \"display-name\": \"Pull image before creating the container\",\n" +
" \"default-value\": \"false\",\n" +
" },\n" +
" \"docker_client_cert\": {\n" +
" \"display-name\": \"Docker Client Certificate\",\n" +
" \"required\": false,\n" +
" \"secure\": true,\n" +
" \"display-order\": \"7\"\n" +
" },\n" +
" \"auto_register_timeout\": {\n" +
" \"display-name\": \"Agent auto-register Timeout (in minutes)\",\n" +
" \"default-value\": \"10\",\n" +
" \"required\": true,\n" +
" \"secure\": false,\n" +
" \"display-order\": \"13\"\n" +
" }" +
"}\n";
" \"display-order\": \"4\"\n" +
" }\n" +
"}";
JSONAssert.assertEquals(expectedJSON, response.responseBody(), true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,54 @@
import static org.hamcrest.Matchers.nullValue;

public class GoServerURLFieldTest {

private final String displayName = "Go Server Url";
private final GoServerURLField goServerURLField = new GoServerURLField("0");

@Test
public void shouldCheckBlankInput() {
String result = goServerURLField.doValidate("");

assertThat(result, is(this.displayName + " must not be blank."));
assertThat(result, is("Go Server URL must not be blank."));
}

@Test
public void shouldCheckIfStringIsValidUrl() {
String result = goServerURLField.doValidate("foobar");

assertThat(result, is(this.displayName + " must be a valid URL (https://example.com:8154/go)"));
assertThat(result, is("Go Server URL must be a valid URL (https://example.com:8154/go)"));
}

@Test
public void shouldCheckIfSchemeIsValid() {
String result = goServerURLField.doValidate("example.com");

assertThat(result, is(this.displayName + " must be a valid URL (https://example.com:8154/go)"));
assertThat(result, is("Go Server URL must be a valid URL (https://example.com:8154/go)"));
}

@Test
public void shouldCheckIfSchemeIsHTTPS() {
String result = goServerURLField.doValidate("http://example.com");

assertThat(result, is(this.displayName + " must be a valid HTTPs URL (https://example.com:8154/go)"));
assertThat(result, is("Go Server URL must be a valid HTTPs URL (https://example.com:8154/go)"));
}

@Test
public void shouldCheckForLocalhost() {
String result = goServerURLField.doValidate("https://localhost:8154/go");

assertThat(result, is(this.displayName + " must not be localhost, since this gets resolved on the agents"));
assertThat(result, is("Go Server URL must not be localhost, since this gets resolved on the agents"));

result = goServerURLField.doValidate("https://127.0.0.1:8154/go");

assertThat(result, is(this.displayName + " must not be localhost, since this gets resolved on the agents"));
assertThat(result, is("Go Server URL must not be localhost, since this gets resolved on the agents"));
}

@Test
public void shouldCheckIfUrlEndsWithContextGo() {
String result = goServerURLField.doValidate("https://example.com:8154/");
assertThat(result, is(this.displayName + " must be a valid URL ending with '/go' (https://example.com:8154/go)"));
assertThat(result, is("Go Server URL must be a valid URL ending with '/go' (https://example.com:8154/go)"));

result = goServerURLField.doValidate("https://example.com:8154/crimemastergogo");
assertThat(result, is(this.displayName + " must be a valid URL ending with '/go' (https://example.com:8154/go)"));
assertThat(result, is("Go Server URL must be a valid URL ending with '/go' (https://example.com:8154/go)"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ public void shouldValidateABadConfiguration() throws Exception {
" \"key\": \"go_server_url\"\n" +
" },\n" +
" {\n" +
" \"message\": \"Maximum containers to allow must be a positive integer.\",\n" +
" \"key\": \"max_docker_containers\"\n" +
" }\n," +
" {\n" +
" \"message\": \"Docker URI must not be blank.\",\n" +
" \"key\": \"docker_uri\"\n" +
" },\n" +
" {\n" +
" \"message\": \"Maximum containers to allow must be a positive integer.\",\n" +
" \"key\": \"max_docker_containers\"\n" +
" },\n" +
" {\n" +
" \"message\": \"Agent auto-register Timeout (in minutes) must be a positive integer.\",\n" +
" \"key\": \"auto_register_timeout\"\n" +
" }\n" +
"]\n", response.responseBody(), true);
"]", response.responseBody(), true);
}

@Test
Expand All @@ -70,7 +70,6 @@ public void shouldValidateAGoodConfiguration() throws Exception {
JSONAssert.assertEquals("[]", response.responseBody(), true);
}


@Test
public void shouldValidateAConfigurationWithAllPrivateRegistryInfos() throws Exception {
ValidatePluginSettings settings = new ValidatePluginSettings();
Expand Down Expand Up @@ -152,9 +151,21 @@ public void shouldNotValidateAConfigurationWithInvalidPrivateRegistryCustomCreds
settings.put("pull_on_container_create", "false");
GoPluginApiResponse response = new ValidateConfigurationExecutor(settings).execute();

String expectedString = "[{\"message\":\"Private Registry Server must not be blank.\",\"key\":\"private_registry_server\"}," +
"{\"message\":\"Private Registry Username must not be blank.\",\"key\":\"private_registry_username\"}," +
"{\"message\":\"Private Registry Password must not be blank.\",\"key\":\"private_registry_password\"}]";
String expectedString = "[\n" +
" {\n" +
" \"message\": \"Private Registry Username must not be blank.\",\n" +
" \"key\": \"private_registry_username\"\n" +
" },\n" +
" {\n" +
" \"message\": \"Private Registry Server must not be blank.\",\n" +
" \"key\": \"private_registry_server\"\n" +
" },\n" +
" {\n" +
" \"message\": \"Private Registry Password must not be blank.\",\n" +
" \"key\": \"private_registry_password\"\n" +
" }\n" +
"]";

assertThat(response.responseCode(), is(200));
JSONAssert.assertEquals(expectedString, response.responseBody(), true);
}
Expand Down

0 comments on commit 5859da9

Please sign in to comment.