-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openstack: added nova server and swift tests #1943
- Loading branch information
1 parent
67a6da5
commit 62c70aa
Showing
15 changed files
with
497 additions
and
78 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
...ain/java/org/apache/camel/quarkus/component/openstack/it/OpenstackNovaServerResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.camel.quarkus.component.openstack.it; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
|
||
import org.apache.camel.CamelExecutionException; | ||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.component.openstack.common.OpenstackConstants; | ||
import org.apache.camel.component.openstack.nova.NovaConstants; | ||
import org.jboss.logging.Logger; | ||
import org.openstack4j.api.Builders; | ||
import org.openstack4j.api.exceptions.ServerResponseException; | ||
import org.openstack4j.model.compute.Server; | ||
import org.openstack4j.model.compute.Server.Status; | ||
import org.openstack4j.model.compute.ServerCreate; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
@Path("/openstack/nova/servers/") | ||
@ApplicationScoped | ||
public class OpenstackNovaServerResource { | ||
|
||
private static final Logger LOG = Logger.getLogger(OpenstackNovaServerResource.class); | ||
|
||
private static final String URI_FORMAT = "openstack-nova://{{camel.openstack.test.host-url}}?username=user&password=secret&project=project&operation=%s&subsystem=" | ||
+ NovaConstants.NOVA_SUBSYSTEM_SERVERS; | ||
|
||
private final String SERVER_NAME = "server-test-1"; | ||
private final String SERVER_ID = "e565cbdb-8e74-4044-ba6e-0155500b2c46"; | ||
private final String SERVER_WRONG_ID = "05184ba3-00ba-4fbc-b7a2-03b62b884931"; | ||
private final String SERVER_SNAPSHOT_NAME = "server-snapshot"; | ||
private final String SERVER_SNAPSHOT_ID = "72f759b3-2576-4bf0-9ac9-7cb4a5b9d541"; | ||
|
||
@Inject | ||
ProducerTemplate template; | ||
|
||
@Path("/createShouldSucceed") | ||
@POST | ||
public void createShouldSucceed() { | ||
LOG.debug("Calling OpenstackNovaServerResource.createShouldSucceed()"); | ||
|
||
ServerCreate in = Builders.server().name(SERVER_NAME).build(); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.CREATE); | ||
Server out = template.requestBody(uri, in, Server.class); | ||
|
||
assertNotNull(out); | ||
assertEquals(SERVER_NAME, out.getName()); | ||
} | ||
|
||
@Path("/createSnapshotShouldSucceed") | ||
@POST | ||
public void createSnapshotShouldSucceed() { | ||
LOG.debug("Calling OpenstackNovaServerResource.createSnapshotShouldSucceed()"); | ||
|
||
Map<String, Object> headers = new HashMap<String, Object>(); | ||
headers.put(OpenstackConstants.ID, SERVER_ID); | ||
headers.put(OpenstackConstants.NAME, SERVER_SNAPSHOT_NAME); | ||
|
||
String uri = String.format(URI_FORMAT, NovaConstants.CREATE_SNAPSHOT); | ||
String out = template.requestBodyAndHeaders(uri, null, headers, String.class); | ||
|
||
assertEquals(SERVER_SNAPSHOT_ID, out); | ||
} | ||
|
||
@Path("/getWrongIdShouldThrow") | ||
@POST | ||
public void getWrongIdShouldThrow() { | ||
LOG.debug("Calling OpenstackNovaServerResource.getWrongIdShouldThrow()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET); | ||
|
||
try { | ||
template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, SERVER_WRONG_ID, Server.class); | ||
fail("Getting nova server with wrong id should throw"); | ||
} catch (Exception ex) { | ||
assertTrue(ex instanceof CamelExecutionException); | ||
assertTrue(((CamelExecutionException) ex).getCause() instanceof ServerResponseException); | ||
} | ||
} | ||
|
||
@Path("/getAllShouldSucceed") | ||
@POST | ||
public void getAllShouldSucceed() { | ||
LOG.debug("Calling OpenstackNovaServerResource.getAllShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET_ALL); | ||
Server[] servers = template.requestBody(uri, null, Server[].class); | ||
|
||
assertNotNull(servers); | ||
assertEquals(1, servers.length); | ||
assertEquals(1, servers[0].getAddresses().getAddresses("private").size()); | ||
assertEquals("192.168.0.3", servers[0].getAddresses().getAddresses("private").get(0).getAddr()); | ||
assertEquals(Status.ACTIVE, servers[0].getStatus()); | ||
assertEquals("new-server-test", servers[0].getName()); | ||
} | ||
|
||
} |
65 changes: 0 additions & 65 deletions
65
...test/src/main/java/org/apache/camel/quarkus/component/openstack/it/OpenstackResource.java
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
...java/org/apache/camel/quarkus/component/openstack/it/OpenstackSwiftContainerResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.camel.quarkus.component.openstack.it; | ||
|
||
import java.util.Map; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
|
||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.component.openstack.common.OpenstackConstants; | ||
import org.apache.camel.component.openstack.swift.SwiftConstants; | ||
import org.jboss.logging.Logger; | ||
import org.openstack4j.model.storage.object.SwiftContainer; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@Path("/openstack/swift/containers/") | ||
@ApplicationScoped | ||
public class OpenstackSwiftContainerResource { | ||
|
||
private static final Logger LOG = Logger.getLogger(OpenstackSwiftContainerResource.class); | ||
|
||
private static final String URI_FORMAT = "openstack-swift://{{camel.openstack.test.host-url}}?username=user&password=secret&project=project&operation=%s&subsystem=" | ||
+ SwiftConstants.SWIFT_SUBSYSTEM_CONTAINERS; | ||
|
||
private static final String CONTAINER_NAME = "myContainer"; | ||
private static final String NAME_BOOK = "Book"; | ||
private static final String NAME_YEAR = "Year"; | ||
|
||
@Inject | ||
ProducerTemplate template; | ||
|
||
@Path("/getAllShouldSucceed") | ||
@POST | ||
public void getAllShouldSucceed() { | ||
LOG.debug("Calling OpenstackSwiftContainerResource.getAllShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET_ALL); | ||
SwiftContainer[] containers = template.requestBody(uri, null, SwiftContainer[].class); | ||
|
||
assertNotNull(containers); | ||
assertEquals(2, containers.length); | ||
assertEquals(100, containers[0].getTotalSize()); | ||
assertEquals("Test", containers[0].getName()); | ||
assertEquals("marktwain", containers[1].getName()); | ||
} | ||
|
||
@Path("/getMetadataShouldSucceed") | ||
@POST | ||
public void getMetadataShouldSucceed() { | ||
LOG.debug("Calling OpenstackSwiftContainerResource.getMetadataShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, SwiftConstants.GET_METADATA); | ||
Map<?, ?> metadata = template.requestBodyAndHeader(uri, null, SwiftConstants.CONTAINER_NAME, CONTAINER_NAME, Map.class); | ||
|
||
assertNotNull(metadata); | ||
assertEquals("2000", metadata.get(NAME_YEAR)); | ||
assertEquals("TestBook", metadata.get(NAME_BOOK)); | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...in/java/org/apache/camel/quarkus/component/openstack/it/OpenstackSwiftObjectResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.camel.quarkus.component.openstack.it; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
|
||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.component.openstack.common.OpenstackConstants; | ||
import org.apache.camel.component.openstack.swift.SwiftConstants; | ||
import org.jboss.logging.Logger; | ||
import org.openstack4j.model.storage.object.SwiftObject; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@Path("/openstack/swift/objects/") | ||
@ApplicationScoped | ||
public class OpenstackSwiftObjectResource { | ||
|
||
private static final Logger LOG = Logger.getLogger(OpenstackSwiftObjectResource.class); | ||
|
||
private static final String URI_FORMAT = "openstack-swift://{{camel.openstack.test.host-url}}?username=user&password=secret&project=project&operation=%s&subsystem=" | ||
+ SwiftConstants.SWIFT_SUBSYSTEM_OBJECTS; | ||
|
||
private static final String OBJECT_CONTAINER_NAME = "test-container"; | ||
private static final String OBJECT_NAME = "test-file"; | ||
|
||
@Inject | ||
ProducerTemplate template; | ||
|
||
@Path("/getShouldSucceed") | ||
@POST | ||
public void getShouldSucceed() { | ||
LOG.debug("Calling OpenstackSwiftObjectResource.getShouldSucceed()"); | ||
|
||
Map<String, Object> headers = new HashMap<>(); | ||
headers.put(SwiftConstants.CONTAINER_NAME, OBJECT_CONTAINER_NAME); | ||
headers.put(SwiftConstants.OBJECT_NAME, OBJECT_NAME); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET); | ||
SwiftObject swiftObject = template.requestBodyAndHeaders(uri, null, headers, SwiftObject.class); | ||
|
||
assertEquals(OBJECT_CONTAINER_NAME, swiftObject.getContainerName()); | ||
assertEquals(OBJECT_NAME, swiftObject.getName()); | ||
assertEquals(15, swiftObject.getSizeInBytes()); | ||
assertEquals("application/json", swiftObject.getMimeType()); | ||
assertEquals("12345678901234567890", swiftObject.getETag()); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...rc/test/java/org/apache/camel/quarkus/component/openstack/it/OpenstackNovaServerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.camel.quarkus.component.openstack.it; | ||
|
||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.post; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(OpenStackTestResource.class) | ||
class OpenstackNovaServerTest { | ||
|
||
@Test | ||
public void createShouldSucceed() { | ||
post("/openstack/nova/servers/createShouldSucceed").then().statusCode(204); | ||
} | ||
|
||
@Test | ||
public void createSnapshotShouldSucceed() { | ||
post("/openstack/nova/servers/createSnapshotShouldSucceed").then().statusCode(204); | ||
} | ||
|
||
@Test | ||
public void getWrongIdShouldThrow() { | ||
post("/openstack/nova/servers/getWrongIdShouldThrow").then().statusCode(204); | ||
} | ||
|
||
@Test | ||
public void getAllShouldSucceed() { | ||
post("/openstack/nova/servers/getAllShouldSucceed").then().statusCode(204); | ||
} | ||
|
||
} |
Oops, something went wrong.