Skip to content

Commit a33e0fc

Browse files
committed
Merge pull request #29 from indigo-dc/devel
Add functional authorization header test
2 parents c7d3385 + c316cd2 commit a33e0fc

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerTest.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import es.upv.i3m.grycap.file.NoNullOrEmptyFile;
2121
import es.upv.i3m.grycap.file.Utf8File;
2222
import es.upv.i3m.grycap.im.exceptions.FileException;
23-
import es.upv.i3m.grycap.im.exceptions.ImClientErrorException;
2423
import es.upv.i3m.grycap.im.exceptions.ImClientException;
2524
import es.upv.i3m.grycap.im.exceptions.ToscaContentTypeNotSupportedException;
2625
import es.upv.i3m.grycap.im.pojo.InfOutputValues;
@@ -109,25 +108,16 @@ public static void setRestClient() {
109108

110109
/**
111110
* Creates a new infrastructure.
111+
*
112+
* @throws ImClientException
112113
*/
113114
@Before
114-
public void createInfrastructure() {
115-
try {
116-
InfrastructureUri newInfrastructureUri = getIm().createInfrastructure(
117-
readFile(TOSCA_FILE_PATH), BodyContentType.TOSCA);
118-
String uri = newInfrastructureUri.getUri();
119-
Assert.assertEquals(false, uri.isEmpty());
120-
setInfrastructureId(newInfrastructureUri.getInfrastructureId());
121-
} catch (ImClientException exception) {
122-
if (exception instanceof ImClientErrorException) {
123-
System.out.println(
124-
"Message: " + ((ImClientErrorException) exception).getMessage());
125-
System.out.println(
126-
"Message: " + ((ImClientErrorException) exception).getCause());
127-
System.out.println("Message: " + ((ImClientErrorException) exception)
128-
.getResponseError().getFormattedErrorMessage());
129-
}
130-
}
115+
public void createInfrastructure() throws ImClientException {
116+
InfrastructureUri newInfrastructureUri = getIm()
117+
.createInfrastructure(readFile(TOSCA_FILE_PATH), BodyContentType.TOSCA);
118+
String uri = newInfrastructureUri.getUri();
119+
Assert.assertEquals(false, uri.isEmpty());
120+
setInfrastructureId(newInfrastructureUri.getInfrastructureId());
131121
}
132122

133123
private String readFile(String filePath) throws FileException {

src/test/java/es/upv/i3m/grycap/im/auth/AuthorizationHeaderTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package es.upv.i3m.grycap.im.auth;
22

33
import es.upv.i3m.grycap.ImTestWatcher;
4+
import es.upv.i3m.grycap.file.NoNullOrEmptyFile;
5+
import es.upv.i3m.grycap.file.Utf8File;
6+
import es.upv.i3m.grycap.im.InfrastructureManager;
7+
import es.upv.i3m.grycap.im.InfrastructureManagerTest;
48
import es.upv.i3m.grycap.im.auth.credential.Credential;
59
import es.upv.i3m.grycap.im.auth.credential.DummyCredential;
610
import es.upv.i3m.grycap.im.auth.credential.im.ImCredential.ImUsernamePasswordCredential;
@@ -11,12 +15,16 @@
1115
import es.upv.i3m.grycap.im.auth.credential.openstack.OpenstackCredential;
1216
import es.upv.i3m.grycap.im.auth.credential.vmrc.VmrcCredential;
1317
import es.upv.i3m.grycap.im.exceptions.ImClientException;
18+
import es.upv.i3m.grycap.im.pojo.InfrastructureUri;
19+
import es.upv.i3m.grycap.im.rest.client.BodyContentType;
20+
import es.upv.i3m.grycap.logger.ImJavaApiLogger;
1421

1522
import org.junit.Assert;
1623
import org.junit.Before;
1724
import org.junit.BeforeClass;
1825
import org.junit.Test;
1926

27+
import java.nio.file.Paths;
2028
import java.util.ArrayList;
2129

2230
public class AuthorizationHeaderTest extends ImTestWatcher {
@@ -34,6 +42,10 @@ public class AuthorizationHeaderTest extends ImTestWatcher {
3442
"id = one ; type = OpenNebula ; username = usr ; password = pwd ; host = host";
3543
private static final String ONE_TK_CREDS =
3644
"id = one ; type = OpenNebula ; token = token ; host = host";
45+
private static final String IM_DUMMY_PROVIDER_URL =
46+
"http://servproject.i3m.upv.es:8811";
47+
private static final String TOSCA_FILE_PATH =
48+
"./src/test/resources/tosca/galaxy_tosca.yaml";
3749

3850
private static AuthorizationHeader ah;
3951

@@ -47,6 +59,40 @@ public void clearAuthorizationHeader() {
4759
ah.setCredentialsAuthInfos(new ArrayList<Credential<?>>());
4860
}
4961

62+
@Test
63+
public void testAuthorizationHeader() throws ImClientException {
64+
// Create authorization headers
65+
AuthorizationHeader authorizationHeader = new AuthorizationHeader();
66+
Credential<?> cred = ImUsernamePasswordCredential.getBuilder()
67+
.withUsername("imuser01").withPassword("invitado").build();
68+
authorizationHeader.addCredential(cred);
69+
cred = VmrcCredential.getBuilder().withUsername("demo").withPassword("demo")
70+
.withHost("http://servproject.i3m.upv.es:8080/vmrc/vmrc").build();
71+
authorizationHeader.addCredential(cred);
72+
cred = DummyCredential.getBuilder().withId("dummy").build();
73+
authorizationHeader.addCredential(cred);
74+
75+
// Check the headers work with the dummy provider
76+
try {
77+
InfrastructureManager im = new InfrastructureManager(
78+
IM_DUMMY_PROVIDER_URL, authorizationHeader.serialize());
79+
String toscaFile =
80+
new NoNullOrEmptyFile(new Utf8File(Paths.get(TOSCA_FILE_PATH)))
81+
.read();
82+
InfrastructureUri newInfrastructureUri =
83+
im.createInfrastructure(toscaFile, BodyContentType.TOSCA);
84+
String uri = newInfrastructureUri.getUri();
85+
Assert.assertEquals(false, uri.isEmpty());
86+
String infId = newInfrastructureUri.getInfrastructureId();
87+
im.destroyInfrastructure(infId);
88+
89+
} catch (ImClientException exception) {
90+
ImJavaApiLogger.severe(InfrastructureManagerTest.class,
91+
exception.getMessage());
92+
Assert.fail();
93+
}
94+
}
95+
5096
@Test
5197
public void testDummyCredentials() throws ImClientException {
5298
Credential<?> cred = DummyCredential.getBuilder().withId("dummy").build();

0 commit comments

Comments
 (0)