From 8bd06831253aac465f981e439dfb8c9793fd5902 Mon Sep 17 00:00:00 2001 From: alpegon Date: Tue, 21 Jun 2016 16:45:51 +0200 Subject: [PATCH 1/3] Separate unit and integration tests --- pom.xml | 21 ++ .../i3m/grycap/im/InfrastructureManager.java | 2 +- .../auth/credentials/AuthorizationHeader.java | 16 ++ .../im/auth/credentials/Credentials.java | 16 ++ .../im/auth/credentials/ServiceProvider.java | 16 ++ .../properties/AuthTokenProperty.java | 16 ++ .../properties/BaseProperties.java | 16 ++ .../properties/BaseUrlProperty.java | 16 ++ .../properties/GenericProperty.java | 37 ++- .../credentials/properties/HostProperty.java | 16 ++ .../OpenStackAuthVersionProperty.java | 16 ++ .../properties/PasswordProperty.java | 16 ++ .../properties/PrivateKeyProperty.java | 24 +- .../properties/ProjectProperty.java | 16 ++ .../credentials/properties/ProxyProperty.java | 16 ++ .../properties/PublicKeyProperty.java | 24 +- .../properties/ServiceNameProperty.java | 16 ++ .../properties/ServiceRegionProperty.java | 16 ++ .../properties/TenantProperty.java | 16 ++ .../credentials/properties/TokenProperty.java | 16 ++ .../properties/UsernameProperty.java | 16 ++ .../providers/AmazonEc2Credentials.java | 16 ++ .../providers/AzureCredentials.java | 20 +- .../providers/DockerCredentials.java | 16 ++ .../providers/DummyCredential.java | 16 ++ .../providers/FogBowCredentials.java | 16 ++ .../credentials/providers/GceCredentials.java | 16 ++ .../providers/GenericCredentials.java | 16 ++ .../credentials/providers/ImCredentials.java | 16 ++ .../providers/KubernetesCredentials.java | 16 ++ .../providers/OcciCredentials.java | 16 ++ .../providers/OpenNebulaCredentials.java | 16 ++ .../providers/OpenStackCredentials.java | 16 ++ .../providers/OpenstackAuthVersion.java | 16 ++ .../providers/VmrcCredentials.java | 16 ++ .../upv/i3m/grycap/im/pojo/ResponseError.java | 5 +- .../i3m/grycap/im/rest/client/ImClient.java | 2 +- .../im/rest/client/ImResponsesReader.java | 1 - .../rest/client/parameters/NoParameter.java | 4 +- .../im/rest/client/parameters/Parameter.java | 6 +- .../im/rest/client/ssl/SslTrustAllClient.java | 2 +- .../java/es/upv/i3m/grycap/ImTestWatcher.java | 84 +++++++ .../java/es/upv/i3m/grycap/file/FileTest.java | 41 +++- ...Test.java => InfrastructureManagerIT.java} | 4 +- .../credentials/AuthorizationHeaderIT.java | 77 ++++++ ...Test.java => CredentialProvidersTest.java} | 220 ++++++++++-------- .../auth/credentials/GenericCredentials.java | 43 ++++ .../im/auth/credentials/PropertiesTest.java | 218 +++++++++++++++++ .../i3m/grycap/im/lang/ImMessagesTest.java | 16 ++ .../im/pojo/PojoDeserializationTest.java | 16 ++ .../es/upv/i3m/grycap/im/pojo/PojoTest.java | 58 ++++- .../{ImClientTest.java => ImClientIT.java} | 4 +- .../client/parameters/NoParameterTest.java | 44 ++++ .../rest/client/parameters/ParameterTest.java | 78 +++++++ .../im/rest/client/ssl/SslClientTest.java | 21 +- .../es/upv/i3m/grycap/logger/LoggerTest.java | 9 +- .../files/double_escaped_lines_result | 1 + 57 files changed, 1413 insertions(+), 133 deletions(-) rename src/test/java/es/upv/i3m/grycap/im/{InfrastructureManagerTest.java => InfrastructureManagerIT.java} (99%) create mode 100644 src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderIT.java rename src/test/java/es/upv/i3m/grycap/im/auth/credentials/{AuthorizationHeaderTest.java => CredentialProvidersTest.java} (50%) create mode 100644 src/test/java/es/upv/i3m/grycap/im/auth/credentials/GenericCredentials.java create mode 100644 src/test/java/es/upv/i3m/grycap/im/auth/credentials/PropertiesTest.java rename src/test/java/es/upv/i3m/grycap/im/rest/client/{ImClientTest.java => ImClientIT.java} (95%) create mode 100644 src/test/java/es/upv/i3m/grycap/im/rest/client/parameters/NoParameterTest.java create mode 100644 src/test/java/es/upv/i3m/grycap/im/rest/client/parameters/ParameterTest.java create mode 100644 src/test/resources/files/double_escaped_lines_result diff --git a/pom.xml b/pom.xml index 31f5cd6..91ac85b 100644 --- a/pom.xml +++ b/pom.xml @@ -193,6 +193,27 @@ + + org.apache.maven.plugins + maven-failsafe-plugin + 2.17 + + + + integration-test + verify + + + + + + maven-surefire-plugin + + + ch.qos.logback:logback-classic + + + \ No newline at end of file diff --git a/src/main/java/es/upv/i3m/grycap/im/InfrastructureManager.java b/src/main/java/es/upv/i3m/grycap/im/InfrastructureManager.java index fbcb26f..cf7bc1b 100644 --- a/src/main/java/es/upv/i3m/grycap/im/InfrastructureManager.java +++ b/src/main/java/es/upv/i3m/grycap/im/InfrastructureManager.java @@ -405,7 +405,7 @@ public VirtualMachineInfo alterVm(String infId, String vmId, String radlFile, * @param bodyContentType * : type of the content sent in the body of the message */ - private void failIfToscaContentType(BodyContentType bodyContentType) + private static void failIfToscaContentType(BodyContentType bodyContentType) throws ImClientException { if (bodyContentType.equals(BodyContentType.TOSCA)) { ImJavaApiLogger.severe(InfrastructureManager.class, diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeader.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeader.java index 04562aa..56c1a8d 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeader.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeader.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials; import java.util.ArrayList; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/Credentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/Credentials.java index fc8a42c..a2b7852 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/Credentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/Credentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials; public interface Credentials { diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/ServiceProvider.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/ServiceProvider.java index f379283..0107042 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/ServiceProvider.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/ServiceProvider.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials; public enum ServiceProvider { diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/AuthTokenProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/AuthTokenProperty.java index 24975b7..8bfa4af 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/AuthTokenProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/AuthTokenProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/BaseProperties.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/BaseProperties.java index fba4808..0122980 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/BaseProperties.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/BaseProperties.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/BaseUrlProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/BaseUrlProperty.java index 5657487..595bb19 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/BaseUrlProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/BaseUrlProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/GenericProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/GenericProperty.java index f21169d..007920c 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/GenericProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/GenericProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; @@ -7,6 +23,8 @@ public class GenericProperty implements Credentials { private final Credentials credential; private String propertyName; private String propertyValue; + private final String errorMessage; + private static final String NULL_CREDENTIALS = "Empty credentials error."; /** * Generic constructor for all the properties that the authorization header @@ -16,10 +34,8 @@ public GenericProperty(Credentials credential, String propertyName, String propertyValue, String errorMessage) { this.credential = credential; this.propertyName = propertyName; - if (isNullOrEmpty(propertyValue)) { - throw new IllegalArgumentException(errorMessage); - } this.propertyValue = propertyValue; + this.errorMessage = errorMessage; } protected String getPropertyValue() { @@ -32,11 +48,18 @@ protected Credentials getCredentials() { @Override public String serialize() { - StringBuilder credentials = new StringBuilder(credential.serialize()); - if (!isNullOrEmpty(propertyValue)) { - credentials.append(" ; " + propertyName + " = ").append(propertyValue); + if (credential != null) { + StringBuilder credentials = new StringBuilder(credential.serialize()); + if (!isNullOrEmpty(propertyValue)) { + credentials.append(" ; " + propertyName + " = ").append(propertyValue); + } else { + throw new IllegalArgumentException(errorMessage); + } + return credentials.toString(); + } else { + throw new NullPointerException(NULL_CREDENTIALS); } - return credentials.toString(); + } } diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/HostProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/HostProperty.java index 2146b66..de322e6 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/HostProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/HostProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/OpenStackAuthVersionProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/OpenStackAuthVersionProperty.java index 792c201..00f43ab 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/OpenStackAuthVersionProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/OpenStackAuthVersionProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/PasswordProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/PasswordProperty.java index 80608df..f835815 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/PasswordProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/PasswordProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/PrivateKeyProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/PrivateKeyProperty.java index 259ded7..a70540b 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/PrivateKeyProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/PrivateKeyProperty.java @@ -1,14 +1,30 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; public class PrivateKeyProperty extends GenericProperty { - private static final String PROPERTY_NAME = "public_key"; - private static final String ERROR_MESSAGE = "Public key must not be blank"; + private static final String PROPERTY_NAME = "private_key"; + private static final String ERROR_MESSAGE = "Private key must not be blank"; - public PrivateKeyProperty(Credentials credential, String publicKey) { - super(credential, PROPERTY_NAME, publicKey, ERROR_MESSAGE); + public PrivateKeyProperty(Credentials credential, String privateKey) { + super(credential, PROPERTY_NAME, privateKey, ERROR_MESSAGE); } } diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ProjectProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ProjectProperty.java index 4cd7745..d2919b5 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ProjectProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ProjectProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ProxyProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ProxyProperty.java index 4a1e809..2d6a82a 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ProxyProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ProxyProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/PublicKeyProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/PublicKeyProperty.java index 160ebd1..0a28987 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/PublicKeyProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/PublicKeyProperty.java @@ -1,14 +1,30 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; public class PublicKeyProperty extends GenericProperty { - private static final String PROPERTY_NAME = "private_key"; - private static final String ERROR_MESSAGE = "Private key must not be blank"; + private static final String PROPERTY_NAME = "public_key"; + private static final String ERROR_MESSAGE = "Public key must not be blank"; - public PublicKeyProperty(Credentials credential, String privateKey) { - super(credential, PROPERTY_NAME, privateKey, ERROR_MESSAGE); + public PublicKeyProperty(Credentials credential, String publicKey) { + super(credential, PROPERTY_NAME, publicKey, ERROR_MESSAGE); } } diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ServiceNameProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ServiceNameProperty.java index 58e7d94..769f614 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ServiceNameProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ServiceNameProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ServiceRegionProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ServiceRegionProperty.java index 4a0eb0e..3945ec5 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ServiceRegionProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/ServiceRegionProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/TenantProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/TenantProperty.java index 6825d03..50afac5 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/TenantProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/TenantProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/TokenProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/TokenProperty.java index a2b206c..b676949 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/TokenProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/TokenProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/UsernameProperty.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/UsernameProperty.java index e79bced..e17a6e2 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/UsernameProperty.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/properties/UsernameProperty.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.properties; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/AmazonEc2Credentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/AmazonEc2Credentials.java index c45caff..5ad665e 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/AmazonEc2Credentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/AmazonEc2Credentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.ServiceProvider; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/AzureCredentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/AzureCredentials.java index ed78200..2e2c39c 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/AzureCredentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/AzureCredentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.ServiceProvider; @@ -15,12 +31,12 @@ public static AzureCredentials buildCredentials() { } public AzureCredentials withPublicKey(String publicKey) { - setCredentials(new PublicKeyProperty(getCredentials(), publicKey)); + setCredentials(new PrivateKeyProperty(getCredentials(), publicKey)); return this; } public AzureCredentials withPrivateKey(String privateKey) { - setCredentials(new PrivateKeyProperty(getCredentials(), privateKey)); + setCredentials(new PublicKeyProperty(getCredentials(), privateKey)); return this; } diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/DockerCredentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/DockerCredentials.java index d60971c..ed5fe0a 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/DockerCredentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/DockerCredentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.ServiceProvider; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/DummyCredential.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/DummyCredential.java index a31c6c1..0b5181b 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/DummyCredential.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/DummyCredential.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.ServiceProvider; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/FogBowCredentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/FogBowCredentials.java index 9f1c024..b1af293 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/FogBowCredentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/FogBowCredentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.ServiceProvider; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/GceCredentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/GceCredentials.java index a58ab92..10bb4de 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/GceCredentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/GceCredentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.ServiceProvider; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/GenericCredentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/GenericCredentials.java index 434af7f..2164c47 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/GenericCredentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/GenericCredentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.Credentials; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/ImCredentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/ImCredentials.java index e343cc9..277ae5c 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/ImCredentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/ImCredentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.ServiceProvider; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/KubernetesCredentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/KubernetesCredentials.java index 58e2068..2daa1b8 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/KubernetesCredentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/KubernetesCredentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.ServiceProvider; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OcciCredentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OcciCredentials.java index 20d4563..b2fcafe 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OcciCredentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OcciCredentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.ServiceProvider; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OpenNebulaCredentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OpenNebulaCredentials.java index 4d6e8a2..8de125d 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OpenNebulaCredentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OpenNebulaCredentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.ServiceProvider; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OpenStackCredentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OpenStackCredentials.java index 4a47269..5d1ae07 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OpenStackCredentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OpenStackCredentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.ServiceProvider; diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OpenstackAuthVersion.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OpenstackAuthVersion.java index 57f9d60..668910f 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OpenstackAuthVersion.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/OpenstackAuthVersion.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; public enum OpenstackAuthVersion { diff --git a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/VmrcCredentials.java b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/VmrcCredentials.java index 9f6a91e..d92c22b 100644 --- a/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/VmrcCredentials.java +++ b/src/main/java/es/upv/i3m/grycap/im/auth/credentials/providers/VmrcCredentials.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials.providers; import es.upv.i3m.grycap.im.auth.credentials.ServiceProvider; diff --git a/src/main/java/es/upv/i3m/grycap/im/pojo/ResponseError.java b/src/main/java/es/upv/i3m/grycap/im/pojo/ResponseError.java index a9c313b..a5d60c1 100644 --- a/src/main/java/es/upv/i3m/grycap/im/pojo/ResponseError.java +++ b/src/main/java/es/upv/i3m/grycap/im/pojo/ResponseError.java @@ -6,8 +6,11 @@ import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; -public class ResponseError { +import java.io.Serializable; +public class ResponseError implements Serializable { + + private static final long serialVersionUID = 79790631011270851L; private final String message; private final Integer code; diff --git a/src/main/java/es/upv/i3m/grycap/im/rest/client/ImClient.java b/src/main/java/es/upv/i3m/grycap/im/rest/client/ImClient.java index 9434855..a315a65 100644 --- a/src/main/java/es/upv/i3m/grycap/im/rest/client/ImClient.java +++ b/src/main/java/es/upv/i3m/grycap/im/rest/client/ImClient.java @@ -230,7 +230,7 @@ private void logCallContent(final HttpMethods httpMethodUsed, * : content of the call body * @return : the same body content if not null and an empty string if null */ - private String normalizeBodyContent(final String bodyContent) { + private static String normalizeBodyContent(final String bodyContent) { if (bodyContent != null) { return bodyContent; } else { diff --git a/src/main/java/es/upv/i3m/grycap/im/rest/client/ImResponsesReader.java b/src/main/java/es/upv/i3m/grycap/im/rest/client/ImResponsesReader.java index 0418e3b..ee3fba6 100644 --- a/src/main/java/es/upv/i3m/grycap/im/rest/client/ImResponsesReader.java +++ b/src/main/java/es/upv/i3m/grycap/im/rest/client/ImResponsesReader.java @@ -32,7 +32,6 @@ public class ImResponsesReader implements MessageBodyReader { @Override public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { - // TODO make this condition less generic return true; } diff --git a/src/main/java/es/upv/i3m/grycap/im/rest/client/parameters/NoParameter.java b/src/main/java/es/upv/i3m/grycap/im/rest/client/parameters/NoParameter.java index 64d3b14..4090082 100644 --- a/src/main/java/es/upv/i3m/grycap/im/rest/client/parameters/NoParameter.java +++ b/src/main/java/es/upv/i3m/grycap/im/rest/client/parameters/NoParameter.java @@ -21,6 +21,8 @@ */ public class NoParameter implements RestParameter { + private static final Object[] value = new Object[0]; + @Override public void addValue(Object value) { // No need to add anything @@ -33,6 +35,6 @@ public String getName() { @Override public Object[] getValues() { - return new Object[0]; + return value; } } diff --git a/src/main/java/es/upv/i3m/grycap/im/rest/client/parameters/Parameter.java b/src/main/java/es/upv/i3m/grycap/im/rest/client/parameters/Parameter.java index fc5711c..d9ab83f 100644 --- a/src/main/java/es/upv/i3m/grycap/im/rest/client/parameters/Parameter.java +++ b/src/main/java/es/upv/i3m/grycap/im/rest/client/parameters/Parameter.java @@ -41,13 +41,13 @@ public Parameter(String name) { * * @param name * : name of the parameter - * @param values + * @param value * : value of the parameter */ - public Parameter(String name, Object values) { + public Parameter(String name, Object value) { this.name = name; this.values = new ArrayList<>(); - addValue(values); + addValue(value); } /** diff --git a/src/main/java/es/upv/i3m/grycap/im/rest/client/ssl/SslTrustAllClient.java b/src/main/java/es/upv/i3m/grycap/im/rest/client/ssl/SslTrustAllClient.java index 50e7e20..d897952 100644 --- a/src/main/java/es/upv/i3m/grycap/im/rest/client/ssl/SslTrustAllClient.java +++ b/src/main/java/es/upv/i3m/grycap/im/rest/client/ssl/SslTrustAllClient.java @@ -34,7 +34,7 @@ public class SslTrustAllClient implements RestClient { - private TrustManager[] getCerts() { + private static TrustManager[] getCerts() { return new TrustManager[] { new X509TrustManager() { @Override public X509Certificate[] getAcceptedIssuers() { diff --git a/src/test/java/es/upv/i3m/grycap/ImTestWatcher.java b/src/test/java/es/upv/i3m/grycap/ImTestWatcher.java index e708d06..d09b426 100644 --- a/src/test/java/es/upv/i3m/grycap/ImTestWatcher.java +++ b/src/test/java/es/upv/i3m/grycap/ImTestWatcher.java @@ -1,14 +1,48 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap; import es.upv.i3m.grycap.logger.ImJavaApiLogger; +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.WriterAppender; +import org.junit.After; +import org.junit.Before; import org.junit.Rule; import org.junit.rules.TestRule; import org.junit.rules.TestWatcher; import org.junit.runner.Description; +import java.io.StringWriter; + +/** + * This class is used to log the names of the tests executed. It also redirects + * the logger to an internal String instead of displaying the output in the + * console during the execution of the test, so we can check the outputs of the + * tests. + */ public class ImTestWatcher { + private static final StringWriter stringWriter = new StringWriter(); + private static final String STRING_APPENDER_NAME = "StringAppender"; + @Rule public TestRule watcher = new TestWatcher() { protected void starting(Description description) { @@ -16,4 +50,54 @@ protected void starting(Description description) { "Starting test '" + description.getMethodName() + "'"); } }; + + @Before + public void setStringLogger() { + removeAppenders(); + createStringAppender(); + } + + @After + public void cleanLogger() { + cleanStringBuffer(); + removeAppenders(); + createConsoleAppender(); + } + + /** + * Instead of creating a new string writer we set the internal buffer of the + * writer to 0. + */ + private void cleanStringBuffer() { + StringBuffer buf = stringWriter.getBuffer(); + buf.setLength(0); + } + + private void createStringAppender() { + WriterAppender appender = new WriterAppender(); + appender.setName(STRING_APPENDER_NAME); + appender.setLayout(new PatternLayout()); + appender.activateOptions(); + appender.setWriter(stringWriter); + Logger.getLogger(ImJavaApiLogger.class).addAppender(appender); + } + + private void createConsoleAppender() { + ConsoleAppender appender = new ConsoleAppender(); + appender.setName(STRING_APPENDER_NAME); + appender.setLayout(new PatternLayout( + "%-5p %d{yyyy-MM-dd HH:mm:ss.SSS 'GMT'Z} %c{1} [%t] - %m%n")); + appender.activateOptions(); + appender.setThreshold(Level.DEBUG); + Logger.getLogger(ImJavaApiLogger.class).addAppender(appender); + } + + private void removeAppenders() { + Logger.getLogger(ImJavaApiLogger.class).removeAllAppenders(); + } + + public String getLogOutput() { + return stringWriter.toString().trim(); + } + } diff --git a/src/test/java/es/upv/i3m/grycap/file/FileTest.java b/src/test/java/es/upv/i3m/grycap/file/FileTest.java index 47185f0..ba230f3 100644 --- a/src/test/java/es/upv/i3m/grycap/file/FileTest.java +++ b/src/test/java/es/upv/i3m/grycap/file/FileTest.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.file; import es.upv.i3m.grycap.ImTestWatcher; @@ -24,6 +40,8 @@ public class FileTest extends ImTestWatcher { "./src/test/resources/files/aut_one_internal_path_expected_result"; private static final String AUTH_FILE_PATH_SEVERAL_DIFFERENT_INTERNAL_PATH_RESULT_FILE = "./src/test/resources/files/aut_several_different_internal_path_expected_result"; + private static final String DOUBLE_ESCAPED_LINES_RESULT_FILE = + "./src/test/resources/files/double_escaped_lines_result"; @Test public void testNoInternalPaths() throws FileException { @@ -36,6 +54,16 @@ public void testNoInternalPaths() throws FileException { fileContent.toCharArray()); } + @Test + public void testDoubleEscapedLines() throws FileException { + String fileContent = + new DoubleEscapeNewLinesFile(getFile(AUTH_FILE_PATH_NO_INTERNAL_PATH)) + .read(); + String expectedContent = readFile(DOUBLE_ESCAPED_LINES_RESULT_FILE); + Assert.assertEquals(expectedContent, fileContent); + + } + @Test public void testInternalPath() throws FileException { String fileContent = new FileWithInternalPath( @@ -60,12 +88,16 @@ public void testEmptyFileInInternalPath() throws FileException { @Test public void testSeveralDifferentInternalPaths() throws FileException { - String fileContent = new FileWithInternalPath(new EscapeNewLinesFile( - getFile(AUTH_FILE_PATH_SEVERAL_DIFFERENT_INTERNAL_PATH))).read(); + FileWithInternalPath file = new FileWithInternalPath(new EscapeNewLinesFile( + getFile(AUTH_FILE_PATH_SEVERAL_DIFFERENT_INTERNAL_PATH))); + String fileContent = file.read(); String expectedContent = readFile(AUTH_FILE_PATH_SEVERAL_DIFFERENT_INTERNAL_PATH_RESULT_FILE); + Assert.assertArrayEquals(expectedContent.toCharArray(), fileContent.toCharArray()); + Assert.assertEquals(AUTH_FILE_PATH_SEVERAL_DIFFERENT_INTERNAL_PATH, + file.getFilePath().toString()); } @Test @@ -78,6 +110,11 @@ public void testDifferentDecoratorOrder() throws FileException { fileContent.toCharArray()); } + @Test(expected = FileException.class) + public void testFileException() throws FileException { + getFile("").read(); + } + private File getFile(String filePath) throws FileException { return new NoNullOrEmptyFile(new Utf8File(Paths.get(filePath))); } diff --git a/src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerTest.java b/src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerIT.java similarity index 99% rename from src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerTest.java rename to src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerIT.java index c66dbf4..4fd6f04 100644 --- a/src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerTest.java +++ b/src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerIT.java @@ -43,7 +43,7 @@ import java.util.List; import java.util.Map; -public class InfrastructureManagerTest extends ImTestWatcher { +public class InfrastructureManagerIT extends ImTestWatcher { private static InfrastructureManager im; private String infrastructureId; @@ -100,7 +100,7 @@ public static void setRestClient() { im = new InfrastructureManager(IM_DUMMY_PROVIDER_URL, Paths.get(AUTH_FILE_PATH)); } catch (ImClientException exception) { - ImJavaApiLogger.severe(InfrastructureManagerTest.class, + ImJavaApiLogger.severe(InfrastructureManagerIT.class, exception.getMessage()); Assert.fail(); } diff --git a/src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderIT.java b/src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderIT.java new file mode 100644 index 0000000..ca70906 --- /dev/null +++ b/src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderIT.java @@ -0,0 +1,77 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package es.upv.i3m.grycap.im.auth.credentials; + +import es.upv.i3m.grycap.file.NoNullOrEmptyFile; +import es.upv.i3m.grycap.file.Utf8File; +import es.upv.i3m.grycap.im.InfrastructureManager; +import es.upv.i3m.grycap.im.InfrastructureManagerIT; +import es.upv.i3m.grycap.im.auth.credentials.providers.DummyCredential; +import es.upv.i3m.grycap.im.auth.credentials.providers.ImCredentials; +import es.upv.i3m.grycap.im.auth.credentials.providers.VmrcCredentials; +import es.upv.i3m.grycap.im.exceptions.ImClientException; +import es.upv.i3m.grycap.im.pojo.InfrastructureUri; +import es.upv.i3m.grycap.im.rest.client.BodyContentType; +import es.upv.i3m.grycap.logger.ImJavaApiLogger; + +import org.junit.Assert; +import org.junit.Test; + +import java.nio.file.Paths; + +public class AuthorizationHeaderIT extends GenericCredentials { + + // IM information + private static final String IM_DUMMY_PROVIDER_URL = + "http://servproject.i3m.upv.es:8811"; + private static final String TOSCA_FILE_PATH = + "./src/test/resources/tosca/galaxy_tosca.yaml"; + + @Test + public void testAuthorizationHeader() throws ImClientException { + // Create authorization headers + Credentials cred = ImCredentials.buildCredentials().withUsername("imuser01") + .withPassword("invitado"); + getAuthorizationHeader().addCredential(cred); + cred = VmrcCredentials.buildCredentials().withUsername("demo") + .withPassword("demo") + .withHost("http://servproject.i3m.upv.es:8080/vmrc/vmrc"); + getAuthorizationHeader().addCredential(cred); + cred = DummyCredential.buildCredentials(); + getAuthorizationHeader().addCredential(cred); + + // Check the headers work with the dummy provider + try { + InfrastructureManager im = new InfrastructureManager( + IM_DUMMY_PROVIDER_URL, getAuthorizationHeader()); + String toscaFile = + new NoNullOrEmptyFile(new Utf8File(Paths.get(TOSCA_FILE_PATH))) + .read(); + InfrastructureUri newInfrastructureUri = + im.createInfrastructure(toscaFile, BodyContentType.TOSCA); + String uri = newInfrastructureUri.getUri(); + Assert.assertEquals(false, uri.isEmpty()); + String infId = newInfrastructureUri.getInfrastructureId(); + im.destroyInfrastructure(infId); + + } catch (ImClientException exception) { + ImJavaApiLogger.severe(InfrastructureManagerIT.class, + exception.getMessage()); + Assert.fail(); + } + } +} diff --git a/src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderTest.java b/src/test/java/es/upv/i3m/grycap/im/auth/credentials/CredentialProvidersTest.java similarity index 50% rename from src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderTest.java rename to src/test/java/es/upv/i3m/grycap/im/auth/credentials/CredentialProvidersTest.java index 791537e..3d5454d 100644 --- a/src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderTest.java +++ b/src/test/java/es/upv/i3m/grycap/im/auth/credentials/CredentialProvidersTest.java @@ -1,11 +1,23 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.auth.credentials; -import es.upv.i3m.grycap.ImTestWatcher; -import es.upv.i3m.grycap.file.NoNullOrEmptyFile; -import es.upv.i3m.grycap.file.Utf8File; -import es.upv.i3m.grycap.im.InfrastructureManager; -import es.upv.i3m.grycap.im.InfrastructureManagerTest; import es.upv.i3m.grycap.im.auth.credentials.providers.AmazonEc2Credentials; +import es.upv.i3m.grycap.im.auth.credentials.providers.AzureCredentials; import es.upv.i3m.grycap.im.auth.credentials.providers.DockerCredentials; import es.upv.i3m.grycap.im.auth.credentials.providers.DummyCredential; import es.upv.i3m.grycap.im.auth.credentials.providers.FogBowCredentials; @@ -17,20 +29,14 @@ import es.upv.i3m.grycap.im.auth.credentials.providers.OpenStackCredentials; import es.upv.i3m.grycap.im.auth.credentials.providers.OpenstackAuthVersion; import es.upv.i3m.grycap.im.auth.credentials.providers.VmrcCredentials; -import es.upv.i3m.grycap.im.exceptions.ImClientException; -import es.upv.i3m.grycap.im.pojo.InfrastructureUri; -import es.upv.i3m.grycap.im.rest.client.BodyContentType; -import es.upv.i3m.grycap.logger.ImJavaApiLogger; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; -import java.nio.file.Paths; import java.util.ArrayList; +import java.util.List; -public class AuthorizationHeaderTest extends ImTestWatcher { +public class CredentialProvidersTest extends GenericCredentials { // Test user/pass private static final String USER = "user"; @@ -47,7 +53,8 @@ public class AuthorizationHeaderTest extends ImTestWatcher { "id = vmrc ; type = VMRC ; " + USER_PASS + " ; host = host"; private static final String OST_CREDS = "id = ost ; type = OpenStack ; " + USER_PASS - + " ; tenant = tenant ; service_region = region ; host = host"; + + " ; tenant = tenant ; service_region = region ; host = host ; base_url = base ;" + + " service_name = name ; auth_token = token"; private static final String OST_CREDS_PASS_3 = "id = ost ; type = OpenStack ; " + USER_PASS + " ; tenant = tenant ; service_region = region ; host = host ; auth_version = 3.X_password"; @@ -62,6 +69,8 @@ public class AuthorizationHeaderTest extends ImTestWatcher { "id = one ; type = OpenNebula ; token = token ; host = host"; private static final String EC2_CREDS = "id = ec2 ; type = EC2 ; " + USER_PASS; + private static final String AZURE_CREDS = "id = azure ; type = Azure ; " + + "username = " + USER + " ; private_key = public ; public_key = private"; private static final String DOCKER_CREDS = "id = docker ; type = Docker ; host = host_url"; private static final String GCE_CREDS = @@ -70,152 +79,117 @@ public class AuthorizationHeaderTest extends ImTestWatcher { "id = kub ; type = Kubernetes ; username = user ; password = pass ; host = host"; private static final String FOG_BOW_CREDS = "id = fog ; type = FogBow ; host = host ; proxy = proxy"; - // IM information - private static final String IM_DUMMY_PROVIDER_URL = - "http://servproject.i3m.upv.es:8811"; - private static final String TOSCA_FILE_PATH = - "./src/test/resources/tosca/galaxy_tosca.yaml"; - - private static AuthorizationHeader ah; - - @BeforeClass - public static void createAuthorizationHeader() { - ah = new AuthorizationHeader(); - } - - @Before - public void clearAuthorizationHeader() { - ah.setCredentialsAuthInfos(new ArrayList()); - } @Test - public void testAuthorizationHeader() throws ImClientException { - // Create authorization headers - Credentials cred = ImCredentials.buildCredentials().withUsername("imuser01") - .withPassword("invitado"); - ah.addCredential(cred); - cred = VmrcCredentials.buildCredentials().withUsername("demo") - .withPassword("demo") - .withHost("http://servproject.i3m.upv.es:8080/vmrc/vmrc"); - ah.addCredential(cred); - cred = DummyCredential.buildCredentials(); - ah.addCredential(cred); - - // Check the headers work with the dummy provider - try { - InfrastructureManager im = - new InfrastructureManager(IM_DUMMY_PROVIDER_URL, ah); - String toscaFile = - new NoNullOrEmptyFile(new Utf8File(Paths.get(TOSCA_FILE_PATH))) - .read(); - InfrastructureUri newInfrastructureUri = - im.createInfrastructure(toscaFile, BodyContentType.TOSCA); - String uri = newInfrastructureUri.getUri(); - Assert.assertEquals(false, uri.isEmpty()); - String infId = newInfrastructureUri.getInfrastructureId(); - im.destroyInfrastructure(infId); - - } catch (ImClientException exception) { - ImJavaApiLogger.severe(InfrastructureManagerTest.class, - exception.getMessage()); - Assert.fail(); - } + public void testServiceProviderEnumMethods() { + Assert.assertEquals(ServiceProvider.DOCKER, + ServiceProvider.valueOf("DOCKER")); + Assert.assertEquals(12, ServiceProvider.values().length); } @Test public void testAmazonEc2UserPassCredentials() { Credentials cred = AmazonEc2Credentials.buildCredentials() .withUsername(USER).withPassword(PASS); - ah.addCredential(cred); - Assert.assertEquals(EC2_CREDS, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(EC2_CREDS, getAuthorizationHeader().serialize()); + } + + @Test + public void testAzureCredentials() { + Credentials cred = AzureCredentials.buildCredentials().withUsername(USER) + .withPublicKey("public").withPrivateKey("private"); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(AZURE_CREDS, getAuthorizationHeader().serialize()); } @Test public void testDockerCredentials() { Credentials cred = DockerCredentials.buildCredentials().withHost("host_url"); - ah.addCredential(cred); - Assert.assertEquals(DOCKER_CREDS, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(DOCKER_CREDS, getAuthorizationHeader().serialize()); } @Test public void testDummyCredentials() { Credentials cred = DummyCredential.buildCredentials(); - ah.addCredential(cred); - Assert.assertEquals(DUMMY_CREDS, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(DUMMY_CREDS, getAuthorizationHeader().serialize()); } @Test public void testFogBowCredentials() { Credentials cred = FogBowCredentials.buildCredentials().withHost("host") .withProxy("proxy"); - ah.addCredential(cred); - Assert.assertEquals(FOG_BOW_CREDS, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(FOG_BOW_CREDS, getAuthorizationHeader().serialize()); } @Test public void testGceUserPwdCredentials() { Credentials cred = GceCredentials.buildCredentials().withUsername(USER) .withPassword(PASS).withProject("testPrj"); - ah.addCredential(cred); - Assert.assertEquals(GCE_CREDS, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(GCE_CREDS, getAuthorizationHeader().serialize()); } @Test public void testImUserPassCredentials() { Credentials cred = ImCredentials.buildCredentials().withUsername(USER).withPassword(PASS); - ah.addCredential(cred); - Assert.assertEquals(IM_UP_CREDS, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(IM_UP_CREDS, getAuthorizationHeader().serialize()); } @Test public void testImTokenCredentials() { Credentials cred = ImCredentials.buildCredentials().withToken("token"); - ah.addCredential(cred); - Assert.assertEquals(IM_TK_CREDS, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(IM_TK_CREDS, getAuthorizationHeader().serialize()); } @Test public void testKubernetesCredentials() { Credentials cred = KubernetesCredentials.buildCredentials() .withUsername(USER).withPassword(PASS).withHost("host"); - ah.addCredential(cred); - Assert.assertEquals(KUB_CREDS, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(KUB_CREDS, getAuthorizationHeader().serialize()); } @Test public void testOcciCredentials() { Credentials cred = OcciCredentials.buildCredentials().withHost("host").withProxy("proxy"); - ah.addCredential(cred); - Assert.assertEquals(OCCI_CREDS, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(OCCI_CREDS, getAuthorizationHeader().serialize()); } @Test public void testOpenNebulaUserPassCredentials() { Credentials cred = OpenNebulaCredentials.buildCredentials() .withUsername(USER).withPassword(PASS).withHost("host"); - ah.addCredential(cred); - Assert.assertEquals(ONE_UP_CREDS, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(ONE_UP_CREDS, getAuthorizationHeader().serialize()); } @Test public void testOpenNebulaTokenCredentials() { Credentials cred = OpenNebulaCredentials.buildCredentials() .withToken("token").withHost("host"); - ah.addCredential(cred); - Assert.assertEquals(ONE_TK_CREDS, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(ONE_TK_CREDS, getAuthorizationHeader().serialize()); } @Test public void testOpenStackCredentials() { - Credentials cred = OpenStackCredentials.buildCredentials() - .withUsername(USER).withPassword(PASS).withTenant("tenant") - .withServiceRegion("region").withHost("host") - .withAuthVersion(OpenstackAuthVersion.PASSWORD_2_0); - ah.addCredential(cred); - Assert.assertEquals(OST_CREDS, ah.serialize()); + Credentials cred = + OpenStackCredentials.buildCredentials().withUsername(USER) + .withPassword(PASS).withTenant("tenant").withServiceRegion("region") + .withHost("host").withAuthVersion(OpenstackAuthVersion.PASSWORD_2_0) + .withBaseUrl("base").withServiceName("name").withAuthToken("token"); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(OST_CREDS, getAuthorizationHeader().serialize()); } @Test @@ -224,8 +198,8 @@ public void testOpenStackCredentialsPassword3() { .withUsername(USER).withPassword(PASS).withTenant("tenant") .withServiceRegion("region").withHost("host") .withAuthVersion(OpenstackAuthVersion.PASSWORD_3_X); - ah.addCredential(cred); - Assert.assertEquals(OST_CREDS_PASS_3, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(OST_CREDS_PASS_3, getAuthorizationHeader().serialize()); } @Test @@ -234,16 +208,70 @@ public void testOpenStackCredentialsPassword3Token() { .withUsername(USER).withPassword(PASS).withTenant("tenant") .withServiceRegion("region").withHost("host") .withAuthVersion(OpenstackAuthVersion.PASSWORD_3_X_TOKEN); - ah.addCredential(cred); - Assert.assertEquals(OST_CREDS_PASS_3_TOKEN, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(OST_CREDS_PASS_3_TOKEN, + getAuthorizationHeader().serialize()); } @Test public void testVmrcCredentials() { Credentials cred = VmrcCredentials.buildCredentials().withUsername(USER) .withPassword(PASS).withHost("host"); - ah.addCredential(cred); - Assert.assertEquals(VMRC_CREDS, ah.serialize()); + getAuthorizationHeader().addCredential(cred); + Assert.assertEquals(VMRC_CREDS, getAuthorizationHeader().serialize()); + } + + @Test(expected = IllegalArgumentException.class) + public void testNullCredentials() { + Credentials cred = VmrcCredentials.buildCredentials().withPassword(PASS) + .withUsername(null).withHost("host"); + getAuthorizationHeader().addCredential(cred); + getAuthorizationHeader().serialize(); + } + + @Test(expected = IllegalArgumentException.class) + public void testEmptyCredentials() { + Credentials cred = VmrcCredentials.buildCredentials().withUsername(""); + getAuthorizationHeader().addCredential(cred); + getAuthorizationHeader().serialize(); } + @Test + public void testAuthorizationHeaderCredentials() { + // Create authorization headers + Credentials cred = + ImCredentials.buildCredentials().withUsername(USER).withPassword(PASS); + getAuthorizationHeader().addCredential(cred); + cred = VmrcCredentials.buildCredentials().withUsername(USER) + .withPassword(PASS).withHost("host"); + getAuthorizationHeader().addCredential(cred); + cred = DummyCredential.buildCredentials(); + getAuthorizationHeader().addCredential(cred); + + String expected = IM_UP_CREDS + "\\n" + VMRC_CREDS + "\\n" + DUMMY_CREDS; + Assert.assertEquals(expected, getAuthorizationHeader().serialize()); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetEmptyAuthorizationHeaderCredentials() { + getAuthorizationHeader().setCredentialsAuthInfos(null); + } + + @Test + public void testAuthorizationHeaderGetCredentials() { + List credentials = new ArrayList(); + Credentials cred = + ImCredentials.buildCredentials().withUsername(USER).withPassword(PASS); + getAuthorizationHeader().addCredential(cred); + credentials.add(cred); + cred = VmrcCredentials.buildCredentials().withUsername(USER) + .withPassword(PASS).withHost("host"); + getAuthorizationHeader().addCredential(cred); + credentials.add(cred); + cred = DummyCredential.buildCredentials(); + getAuthorizationHeader().addCredential(cred); + credentials.add(cred); + + Assert.assertEquals(credentials, getAuthorizationHeader().getCredentials()); + } } diff --git a/src/test/java/es/upv/i3m/grycap/im/auth/credentials/GenericCredentials.java b/src/test/java/es/upv/i3m/grycap/im/auth/credentials/GenericCredentials.java new file mode 100644 index 0000000..086f9cb --- /dev/null +++ b/src/test/java/es/upv/i3m/grycap/im/auth/credentials/GenericCredentials.java @@ -0,0 +1,43 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package es.upv.i3m.grycap.im.auth.credentials; + +import es.upv.i3m.grycap.ImTestWatcher; + +import org.junit.Before; +import org.junit.BeforeClass; + +import java.util.ArrayList; + +public class GenericCredentials extends ImTestWatcher { + + private static AuthorizationHeader ah; + + @BeforeClass + public static void createAuthorizationHeader() { + ah = new AuthorizationHeader(); + } + + @Before + public void clearAuthorizationHeader() { + ah.setCredentialsAuthInfos(new ArrayList()); + } + + protected AuthorizationHeader getAuthorizationHeader() { + return ah; + } +} diff --git a/src/test/java/es/upv/i3m/grycap/im/auth/credentials/PropertiesTest.java b/src/test/java/es/upv/i3m/grycap/im/auth/credentials/PropertiesTest.java new file mode 100644 index 0000000..0f354c3 --- /dev/null +++ b/src/test/java/es/upv/i3m/grycap/im/auth/credentials/PropertiesTest.java @@ -0,0 +1,218 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package es.upv.i3m.grycap.im.auth.credentials; + +import es.upv.i3m.grycap.im.auth.credentials.properties.AuthTokenProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.BaseProperties; +import es.upv.i3m.grycap.im.auth.credentials.properties.BaseUrlProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.GenericProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.HostProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.OpenStackAuthVersionProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.PasswordProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.PrivateKeyProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.ProjectProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.PublicKeyProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.ServiceNameProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.ServiceRegionProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.TenantProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.TokenProperty; +import es.upv.i3m.grycap.im.auth.credentials.properties.UsernameProperty; +import es.upv.i3m.grycap.im.auth.credentials.providers.OpenstackAuthVersion; + +import org.junit.Assert; +import org.junit.Test; + +public class PropertiesTest extends GenericCredentials { + + private static final String ID = "id"; + private static final String TYPE = "type"; + private static final String BP_EXPECTED_RESULT = "id = id ; type = type"; + + private static final BaseProperties BP = new BaseProperties(ID, TYPE); + private static final String PROPERTY_NAME = "name"; + private static final String PROPERTY_VALUE = "value"; + private static final String ERROR_MESSAGE = "message"; + private static final String ERROR_NULL_CREDENTIALS = + "Empty credentials error."; + + @Test + public void testBaseProperties() { + BaseProperties bp = new BaseProperties(ID, TYPE); + Assert.assertEquals(BP_EXPECTED_RESULT, bp.serialize()); + } + + @Test + public void testNullBaseProperties() { + BaseProperties bp = new BaseProperties(null, null); + Assert.assertEquals("", bp.serialize()); + } + + @Test + public void testGenericProperties() { + GenericProperty gp = + new GenericProperty(BP, PROPERTY_NAME, PROPERTY_VALUE, ERROR_MESSAGE); + Assert.assertEquals(BP_EXPECTED_RESULT + " ; name = value", gp.serialize()); + } + + @Test + public void testGenericPropertyNullPropertyValue() { + try { + GenericProperty gp = + new GenericProperty(BP, PROPERTY_NAME, null, ERROR_MESSAGE); + gp.serialize(); + } catch (IllegalArgumentException exception) { + Assert.assertEquals(ERROR_MESSAGE, exception.getMessage()); + } + } + + @Test + public void testGenericPropertyEmptyPropertyValue() { + try { + GenericProperty gp = + new GenericProperty(BP, PROPERTY_NAME, "", ERROR_MESSAGE); + gp.serialize(); + } catch (IllegalArgumentException exception) { + Assert.assertEquals(ERROR_MESSAGE, exception.getMessage()); + } + } + + @Test + public void testGenericPropertyNullCredentials() { + try { + GenericProperty gp = new GenericProperty(null, PROPERTY_NAME, + PROPERTY_VALUE, ERROR_MESSAGE); + gp.serialize(); + } catch (NullPointerException exception) { + Assert.assertEquals(ERROR_NULL_CREDENTIALS, exception.getMessage()); + } + } + + @Test + public void testAuthTokenProperty() { + AuthTokenProperty p = new AuthTokenProperty(BP, PROPERTY_VALUE); + Assert.assertEquals( + BP_EXPECTED_RESULT + " ; auth_token = " + PROPERTY_VALUE, + p.serialize()); + } + + @Test + public void testBaseUrlProperty() { + BaseUrlProperty p = new BaseUrlProperty(BP, PROPERTY_VALUE); + Assert.assertEquals(BP_EXPECTED_RESULT + " ; base_url = " + PROPERTY_VALUE, + p.serialize()); + } + + @Test + public void testHostProperty() { + HostProperty p = new HostProperty(BP, PROPERTY_VALUE); + Assert.assertEquals(BP_EXPECTED_RESULT + " ; host = " + PROPERTY_VALUE, + p.serialize()); + } + + @Test + public void testOpenStackAuthVersionPropertyPassword2() { + OpenStackAuthVersionProperty p = + new OpenStackAuthVersionProperty(BP, OpenstackAuthVersion.PASSWORD_2_0); + Assert.assertEquals(BP_EXPECTED_RESULT, p.serialize()); + } + + @Test + public void testOpenStackAuthVersionPropertyPassword3() { + OpenStackAuthVersionProperty p = + new OpenStackAuthVersionProperty(BP, OpenstackAuthVersion.PASSWORD_3_X); + Assert.assertEquals(BP_EXPECTED_RESULT + " ; auth_version = " + + OpenstackAuthVersion.PASSWORD_3_X.getValue(), p.serialize()); + } + + @Test + public void testOpenStackAuthVersionPropertyPassword3Token() { + OpenStackAuthVersionProperty p = new OpenStackAuthVersionProperty(BP, + OpenstackAuthVersion.PASSWORD_3_X_TOKEN); + Assert.assertEquals( + BP_EXPECTED_RESULT + " ; auth_version = " + + OpenstackAuthVersion.PASSWORD_3_X_TOKEN.getValue(), + p.serialize()); + } + + @Test + public void testPasswordProperty() { + PasswordProperty p = new PasswordProperty(BP, PROPERTY_VALUE); + Assert.assertEquals(BP_EXPECTED_RESULT + " ; password = " + PROPERTY_VALUE, + p.serialize()); + } + + @Test + public void testPrivateKeyProperty() { + PrivateKeyProperty p = new PrivateKeyProperty(BP, PROPERTY_VALUE); + Assert.assertEquals( + BP_EXPECTED_RESULT + " ; private_key = " + PROPERTY_VALUE, + p.serialize()); + } + + @Test + public void testProjectProperty() { + ProjectProperty p = new ProjectProperty(BP, PROPERTY_VALUE); + Assert.assertEquals(BP_EXPECTED_RESULT + " ; project = " + PROPERTY_VALUE, + p.serialize()); + } + + @Test + public void testPublicKeyProperty() { + PublicKeyProperty p = new PublicKeyProperty(BP, PROPERTY_VALUE); + Assert.assertEquals( + BP_EXPECTED_RESULT + " ; public_key = " + PROPERTY_VALUE, + p.serialize()); + } + + @Test + public void testServiceNameProperty() { + ServiceNameProperty p = new ServiceNameProperty(BP, PROPERTY_VALUE); + Assert.assertEquals( + BP_EXPECTED_RESULT + " ; service_name = " + PROPERTY_VALUE, + p.serialize()); + } + + @Test + public void testServiceRegionProperty() { + ServiceRegionProperty p = new ServiceRegionProperty(BP, PROPERTY_VALUE); + Assert.assertEquals( + BP_EXPECTED_RESULT + " ; service_region = " + PROPERTY_VALUE, + p.serialize()); + } + + @Test + public void testTenantProperty() { + TenantProperty p = new TenantProperty(BP, PROPERTY_VALUE); + Assert.assertEquals(BP_EXPECTED_RESULT + " ; tenant = " + PROPERTY_VALUE, + p.serialize()); + } + + @Test + public void testTokenProperty() { + TokenProperty p = new TokenProperty(BP, PROPERTY_VALUE); + Assert.assertEquals(BP_EXPECTED_RESULT + " ; token = " + PROPERTY_VALUE, + p.serialize()); + } + + @Test + public void testUsernameProperty() { + UsernameProperty p = new UsernameProperty(BP, PROPERTY_VALUE); + Assert.assertEquals(BP_EXPECTED_RESULT + " ; username = " + PROPERTY_VALUE, + p.serialize()); + } + +} diff --git a/src/test/java/es/upv/i3m/grycap/im/lang/ImMessagesTest.java b/src/test/java/es/upv/i3m/grycap/im/lang/ImMessagesTest.java index 73752bf..3572b6e 100644 --- a/src/test/java/es/upv/i3m/grycap/im/lang/ImMessagesTest.java +++ b/src/test/java/es/upv/i3m/grycap/im/lang/ImMessagesTest.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.lang; import org.junit.Assert; diff --git a/src/test/java/es/upv/i3m/grycap/im/pojo/PojoDeserializationTest.java b/src/test/java/es/upv/i3m/grycap/im/pojo/PojoDeserializationTest.java index 30c3530..42ec620 100644 --- a/src/test/java/es/upv/i3m/grycap/im/pojo/PojoDeserializationTest.java +++ b/src/test/java/es/upv/i3m/grycap/im/pojo/PojoDeserializationTest.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.pojo; import com.fasterxml.jackson.core.JsonParseException; diff --git a/src/test/java/es/upv/i3m/grycap/im/pojo/PojoTest.java b/src/test/java/es/upv/i3m/grycap/im/pojo/PojoTest.java index 6084343..5c60043 100644 --- a/src/test/java/es/upv/i3m/grycap/im/pojo/PojoTest.java +++ b/src/test/java/es/upv/i3m/grycap/im/pojo/PojoTest.java @@ -1,8 +1,26 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.pojo; import es.upv.i3m.grycap.ImTestWatcher; +import es.upv.i3m.grycap.im.States; import es.upv.i3m.grycap.im.exceptions.FileException; import es.upv.i3m.grycap.im.exceptions.InfrastructureUuidNotFoundException; +import es.upv.i3m.grycap.im.exceptions.NoEnumFoundException; import org.junit.Assert; import org.junit.Test; @@ -21,6 +39,8 @@ public void testInfOutputValuesEquals() { InfOutputValues outputs2 = new InfOutputValues(outputValues); Assert.assertEquals(outputs1, outputs1); Assert.assertEquals(outputs1, outputs2); + Assert.assertEquals(outputs1.hashCode(), outputs2.hashCode()); + Assert.assertFalse(outputs1.equals("")); } @Test @@ -32,6 +52,24 @@ public void testInfOutputValuesNotEquals() { Assert.assertNotEquals(outputs1, outputs3); } + @Test + public void testInfrastructureState() throws NoEnumFoundException { + Map infStates = new HashMap(); + infStates.put("test", "test1"); + infStates.put("test2", "test3"); + InfrastructureState infState = + new InfrastructureState(States.PENDING.getValue(), infStates); + + Assert.assertEquals(States.PENDING, infState.getEnumState()); + Assert.assertEquals(625493770, infState.hashCode()); + Assert.assertFalse(infState.equals("")); + String expected = "Infrastructure state 'pending'\n" + + " - Virtual machine 'test2' state ' test3' - Virtual machine 'test' state ' test1'"; + Assert.assertEquals(expected, + infState.getFormattedInfrastructureStateString()); + + } + @Test public void testInfrastructureStateEquals() { Map infStates = new HashMap(); @@ -60,6 +98,8 @@ public void testInfrastructureUriEquals() { InfrastructureUri uri2 = new InfrastructureUri("uri"); Assert.assertEquals(uri1, uri1); Assert.assertEquals(uri1, uri2); + Assert.assertEquals(uri1.hashCode(), uri1.hashCode()); + Assert.assertFalse(uri1.equals("")); } @Test @@ -76,13 +116,15 @@ public void testInfrastructureUriExtractUuid() "http://127.0.0.1:8800/infrastructures/a71d6e4c-085e-11e6-aa50-f079596e5f16/vms/0/contmsg"); String uuid = uri.getInfrastructureId(); Assert.assertEquals("a71d6e4c-085e-11e6-aa50-f079596e5f16", uuid); + uri.getInfrastructureId(); } @Test(expected = InfrastructureUuidNotFoundException.class) public void testInfrastructureUriExtractUuidNotFound() throws InfrastructureUuidNotFoundException { - InfrastructureUri uri = new InfrastructureUri( - "http://127.0.0.1:8800/infrastructures/a71d6e4c-11e6-aa50-f079596e5f16/vms/0/contmsg"); + // Uri not following the expected pattern + InfrastructureUri uri = + new InfrastructureUri("http://127.0.0.1:8800/9596e5f16/vms/0/contmsg"); uri.getInfrastructureId(); } @@ -94,6 +136,8 @@ public void testInfrastructureUrisEquals() { .asList(new InfrastructureUri("uri"), new InfrastructureUri("uri"))); Assert.assertEquals(uris1, uris1); Assert.assertEquals(uris1, uris2); + Assert.assertEquals(uris1.hashCode(), uris2.hashCode()); + Assert.assertFalse(uris1.equals("")); } @Test @@ -112,6 +156,8 @@ public void testPropertyEquals() { Property prop2 = new Property("key", "value"); Assert.assertEquals(prop1, prop1); Assert.assertEquals(prop1, prop2); + Assert.assertEquals(prop1.hashCode(), prop2.hashCode()); + Assert.assertFalse(prop1.equals("")); } @Test @@ -127,6 +173,8 @@ public void testErrorEquals() { ResponseError error2 = new ResponseError("message", 200); Assert.assertEquals(error1, error1); Assert.assertEquals(error1, error2); + Assert.assertEquals(error1.hashCode(), error2.hashCode()); + Assert.assertFalse(error1.equals("")); } @Test @@ -146,7 +194,9 @@ public void testErrorNotEqualsMessage() { @Test public void testError404() { ResponseError error = new ResponseError("message", 404); - Assert.assertEquals(true, error.is404Error()); + Assert.assertTrue(error.is404Error()); + error = new ResponseError("message", 405); + Assert.assertFalse(error.is404Error()); } @Test @@ -167,6 +217,8 @@ public void testVirtualMachineInfoEquals() throws FileException { Assert.assertEquals(vmInfo1, vmInfo1); Assert.assertEquals(vmInfo1, vmInfo2); + Assert.assertEquals(vmInfo1.hashCode(), vmInfo2.hashCode()); + Assert.assertFalse(vmInfo1.equals("")); } @Test diff --git a/src/test/java/es/upv/i3m/grycap/im/rest/client/ImClientTest.java b/src/test/java/es/upv/i3m/grycap/im/rest/client/ImClientIT.java similarity index 95% rename from src/test/java/es/upv/i3m/grycap/im/rest/client/ImClientTest.java rename to src/test/java/es/upv/i3m/grycap/im/rest/client/ImClientIT.java index 7dea928..60f2048 100644 --- a/src/test/java/es/upv/i3m/grycap/im/rest/client/ImClientTest.java +++ b/src/test/java/es/upv/i3m/grycap/im/rest/client/ImClientIT.java @@ -26,7 +26,7 @@ import org.junit.BeforeClass; import org.junit.Test; -public class ImClientTest extends ImTestWatcher { +public class ImClientIT extends ImTestWatcher { private static ImClient imClient; private static final String IM_DUMMY_PROVIDER_URL = @@ -47,7 +47,7 @@ public static void setRestClient() { try { imClient = new ImClient(IM_DUMMY_PROVIDER_URL, AUTH_FILE_PATH); } catch (ImClientException exception) { - ImJavaApiLogger.severe(ImClientTest.class, exception.getMessage()); + ImJavaApiLogger.severe(ImClientIT.class, exception.getMessage()); Assert.fail(); } } diff --git a/src/test/java/es/upv/i3m/grycap/im/rest/client/parameters/NoParameterTest.java b/src/test/java/es/upv/i3m/grycap/im/rest/client/parameters/NoParameterTest.java new file mode 100644 index 0000000..cae972b --- /dev/null +++ b/src/test/java/es/upv/i3m/grycap/im/rest/client/parameters/NoParameterTest.java @@ -0,0 +1,44 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package es.upv.i3m.grycap.im.rest.client.parameters; + +import es.upv.i3m.grycap.ImTestWatcher; + +import org.junit.Assert; +import org.junit.Test; + +public class NoParameterTest extends ImTestWatcher { + + @Test + public void testNoParameterCreation() { + NoParameter np = new NoParameter(); + Assert.assertArrayEquals(new Object[0], np.getValues()); + } + + @Test + public void testNoParameterName() { + NoParameter np = new NoParameter(); + Assert.assertEquals("", np.getName()); + } + + @Test + public void testNoParameterAddValue() { + NoParameter np = new NoParameter(); + np.addValue("TEST"); + Assert.assertArrayEquals(new Object[0], np.getValues()); + } +} diff --git a/src/test/java/es/upv/i3m/grycap/im/rest/client/parameters/ParameterTest.java b/src/test/java/es/upv/i3m/grycap/im/rest/client/parameters/ParameterTest.java new file mode 100644 index 0000000..60948b9 --- /dev/null +++ b/src/test/java/es/upv/i3m/grycap/im/rest/client/parameters/ParameterTest.java @@ -0,0 +1,78 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package es.upv.i3m.grycap.im.rest.client.parameters; + +import es.upv.i3m.grycap.ImTestWatcher; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ParameterTest extends ImTestWatcher { + + private static final String NAME = "test"; + private static final String VALUE = "value"; + + @Test + public void testParameterWithNameCreation() { + Parameter p = new Parameter(NAME); + Assert.assertEquals(NAME, p.getName()); + Assert.assertArrayEquals(new Object[0], p.getValues()); + } + + @Test + public void testParameterWithNameAndValueCreation() { + Parameter p = new Parameter(NAME, VALUE); + Assert.assertEquals(NAME, p.getName()); + Object[] expected = new Object[] { VALUE }; + Assert.assertArrayEquals(expected, p.getValues()); + } + + @Test + public void testParameterWithNameAndArrayValueCreation() { + List values = Arrays.asList(VALUE, VALUE, VALUE); + Parameter p = new Parameter(NAME, values); + Assert.assertEquals(NAME, p.getName()); + Assert.assertArrayEquals(values.toArray(), p.getValues()); + } + + @Test + public void testParameterWithNameAndNullArrayValueCreation() { + Parameter p = new Parameter(NAME, null); + Assert.assertEquals(NAME, p.getName()); + Assert.assertArrayEquals(new Object[0], p.getValues()); + + String className = p.getClass().getName(); + String errorMessage = "Null or empty list passed as parameter values"; + Assert.assertEquals(className + ": " + errorMessage, getLogOutput()); + } + + @Test + public void testParameterWithNameAndEmptyArrayValueCreation() { + Parameter p = new Parameter(NAME, new ArrayList<>()); + Assert.assertEquals(NAME, p.getName()); + Assert.assertArrayEquals(new Object[0], p.getValues()); + + String className = p.getClass().getName(); + String errorMessage = "Null or empty list passed as parameter values"; + Assert.assertEquals(className + ": " + errorMessage, getLogOutput()); + } + +} diff --git a/src/test/java/es/upv/i3m/grycap/im/rest/client/ssl/SslClientTest.java b/src/test/java/es/upv/i3m/grycap/im/rest/client/ssl/SslClientTest.java index 19f9f5e..5dc1d26 100644 --- a/src/test/java/es/upv/i3m/grycap/im/rest/client/ssl/SslClientTest.java +++ b/src/test/java/es/upv/i3m/grycap/im/rest/client/ssl/SslClientTest.java @@ -1,5 +1,22 @@ +/** + * Copyright (C) GRyCAP - I3M - UPV + * + *

Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package es.upv.i3m.grycap.im.rest.client.ssl; +import es.upv.i3m.grycap.ImTestWatcher; import es.upv.i3m.grycap.im.exceptions.ImClientException; import org.junit.After; @@ -11,7 +28,7 @@ import javax.ws.rs.client.Client; import javax.ws.rs.core.MediaType; -public class SslClientTest { +public class SslClientTest extends ImTestWatcher { private ClientAndServer mockServer; private final String target = "https://127.0.0.1:1080"; @@ -31,6 +48,8 @@ public void testSslClient() throws ImClientException { SslClient sslClient = new SslClient(null, null); Client client = sslClient.createClient(); client.target(target).path("").request(MediaType.TEXT_PLAIN).get(); + + // System.out.println(getLogOutput()); } @Test diff --git a/src/test/java/es/upv/i3m/grycap/logger/LoggerTest.java b/src/test/java/es/upv/i3m/grycap/logger/LoggerTest.java index 96796a4..548804e 100644 --- a/src/test/java/es/upv/i3m/grycap/logger/LoggerTest.java +++ b/src/test/java/es/upv/i3m/grycap/logger/LoggerTest.java @@ -18,37 +18,44 @@ import es.upv.i3m.grycap.ImTestWatcher; import es.upv.i3m.grycap.im.exceptions.AuthorizationFileException; -import es.upv.i3m.grycap.logger.ImJavaApiLogger; +import org.junit.Assert; import org.junit.Test; public class LoggerTest extends ImTestWatcher { private static final String TEST_MESSAGE = "Test Message"; + private static final String CLASS_NAME = LoggerTest.class.getName(); @Test public void testLoggerDebug() { ImJavaApiLogger.debug(this.getClass(), TEST_MESSAGE); + Assert.assertEquals(CLASS_NAME + ": " + TEST_MESSAGE, getLogOutput()); } @Test public void testLoggerInfo() { ImJavaApiLogger.info(this.getClass(), TEST_MESSAGE); + Assert.assertEquals(CLASS_NAME + ": " + TEST_MESSAGE, getLogOutput()); } @Test public void testLoggerWarning() { ImJavaApiLogger.warning(this.getClass(), TEST_MESSAGE); + Assert.assertEquals(CLASS_NAME + ": " + TEST_MESSAGE, getLogOutput()); } @Test public void testLoggerSevereException() { ImJavaApiLogger.severe(this.getClass(), new AuthorizationFileException(TEST_MESSAGE)); + Assert.assertTrue(getLogOutput().contains( + "es.upv.i3m.grycap.im.exceptions.AuthorizationFileException: Test Message")); } @Test public void testLoggerSevereMessage() { ImJavaApiLogger.severe(this.getClass(), TEST_MESSAGE); + Assert.assertEquals(CLASS_NAME + ": " + TEST_MESSAGE, getLogOutput()); } } diff --git a/src/test/resources/files/double_escaped_lines_result b/src/test/resources/files/double_escaped_lines_result new file mode 100644 index 0000000..8437cef --- /dev/null +++ b/src/test/resources/files/double_escaped_lines_result @@ -0,0 +1 @@ +type = InfrastructureManager; username = imuser01; password = invitado\\nid = dummy; type = Dummy;\\ntype = VMRC; host = http://servproject.i3m.upv.es:8080/vmrc/vmrc; username = demo; password = demo; \ No newline at end of file From 22ac8ab5c9bec81df29dc52cb64365754c693ac2 Mon Sep 17 00:00:00 2001 From: alpegon Date: Tue, 21 Jun 2016 17:28:53 +0200 Subject: [PATCH 2/3] Changed back the test separation New test and correct separation will be added after the june release. --- pom.xml | 9 ++++++++- ...tureManagerIT.java => InfrastructureManagerTest.java} | 4 ++-- ...izationHeaderIT.java => AuthorizationHeaderTest.java} | 6 +++--- .../rest/client/{ImClientIT.java => ImClientTest.java} | 4 ++-- 4 files changed, 15 insertions(+), 8 deletions(-) rename src/test/java/es/upv/i3m/grycap/im/{InfrastructureManagerIT.java => InfrastructureManagerTest.java} (99%) rename src/test/java/es/upv/i3m/grycap/im/auth/credentials/{AuthorizationHeaderIT.java => AuthorizationHeaderTest.java} (93%) rename src/test/java/es/upv/i3m/grycap/im/rest/client/{ImClientIT.java => ImClientTest.java} (95%) diff --git a/pom.xml b/pom.xml index 91ac85b..fa5c3d3 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,7 @@ 2.17 3.10.4 0.7.7.201606060606 + 2.0.70-beta @@ -66,13 +67,19 @@ ${junit.version} test - + org.mock-server mockserver-netty ${mockserver-netty.version} test + + + org.mockito + mockito-core + ${mockito.version} + diff --git a/src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerIT.java b/src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerTest.java similarity index 99% rename from src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerIT.java rename to src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerTest.java index 4fd6f04..c66dbf4 100644 --- a/src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerIT.java +++ b/src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerTest.java @@ -43,7 +43,7 @@ import java.util.List; import java.util.Map; -public class InfrastructureManagerIT extends ImTestWatcher { +public class InfrastructureManagerTest extends ImTestWatcher { private static InfrastructureManager im; private String infrastructureId; @@ -100,7 +100,7 @@ public static void setRestClient() { im = new InfrastructureManager(IM_DUMMY_PROVIDER_URL, Paths.get(AUTH_FILE_PATH)); } catch (ImClientException exception) { - ImJavaApiLogger.severe(InfrastructureManagerIT.class, + ImJavaApiLogger.severe(InfrastructureManagerTest.class, exception.getMessage()); Assert.fail(); } diff --git a/src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderIT.java b/src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderTest.java similarity index 93% rename from src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderIT.java rename to src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderTest.java index ca70906..2b85afc 100644 --- a/src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderIT.java +++ b/src/test/java/es/upv/i3m/grycap/im/auth/credentials/AuthorizationHeaderTest.java @@ -19,7 +19,7 @@ import es.upv.i3m.grycap.file.NoNullOrEmptyFile; import es.upv.i3m.grycap.file.Utf8File; import es.upv.i3m.grycap.im.InfrastructureManager; -import es.upv.i3m.grycap.im.InfrastructureManagerIT; +import es.upv.i3m.grycap.im.InfrastructureManagerTest; import es.upv.i3m.grycap.im.auth.credentials.providers.DummyCredential; import es.upv.i3m.grycap.im.auth.credentials.providers.ImCredentials; import es.upv.i3m.grycap.im.auth.credentials.providers.VmrcCredentials; @@ -33,7 +33,7 @@ import java.nio.file.Paths; -public class AuthorizationHeaderIT extends GenericCredentials { +public class AuthorizationHeaderTest extends GenericCredentials { // IM information private static final String IM_DUMMY_PROVIDER_URL = @@ -69,7 +69,7 @@ public void testAuthorizationHeader() throws ImClientException { im.destroyInfrastructure(infId); } catch (ImClientException exception) { - ImJavaApiLogger.severe(InfrastructureManagerIT.class, + ImJavaApiLogger.severe(InfrastructureManagerTest.class, exception.getMessage()); Assert.fail(); } diff --git a/src/test/java/es/upv/i3m/grycap/im/rest/client/ImClientIT.java b/src/test/java/es/upv/i3m/grycap/im/rest/client/ImClientTest.java similarity index 95% rename from src/test/java/es/upv/i3m/grycap/im/rest/client/ImClientIT.java rename to src/test/java/es/upv/i3m/grycap/im/rest/client/ImClientTest.java index 60f2048..7dea928 100644 --- a/src/test/java/es/upv/i3m/grycap/im/rest/client/ImClientIT.java +++ b/src/test/java/es/upv/i3m/grycap/im/rest/client/ImClientTest.java @@ -26,7 +26,7 @@ import org.junit.BeforeClass; import org.junit.Test; -public class ImClientIT extends ImTestWatcher { +public class ImClientTest extends ImTestWatcher { private static ImClient imClient; private static final String IM_DUMMY_PROVIDER_URL = @@ -47,7 +47,7 @@ public static void setRestClient() { try { imClient = new ImClient(IM_DUMMY_PROVIDER_URL, AUTH_FILE_PATH); } catch (ImClientException exception) { - ImJavaApiLogger.severe(ImClientIT.class, exception.getMessage()); + ImJavaApiLogger.severe(ImClientTest.class, exception.getMessage()); Assert.fail(); } } From 1d04825c9583ff0e267b2c9169dd59e4f8d8e978 Mon Sep 17 00:00:00 2001 From: alpegon Date: Tue, 21 Jun 2016 17:34:06 +0200 Subject: [PATCH 3/3] Update minor version due to bug fixing --- pom.xml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index fa5c3d3..325787c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 es.upv.i3m.grycap im-java-api - 0.4.6 + 0.4.7 IM Java API Java client for the REST API of the IM @@ -74,12 +74,6 @@ ${mockserver-netty.version} test - - - org.mockito - mockito-core - ${mockito.version} -