-
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 neutron port, subnet and nova flavor tests #1943
- Loading branch information
1 parent
2937812
commit b90b5f8
Showing
14 changed files
with
487 additions
and
63 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...in/java/org/apache/camel/quarkus/component/openstack/it/OpenstackNeutronPortResource.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,83 @@ | ||
/* | ||
* 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 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.neutron.NeutronConstants; | ||
import org.jboss.logging.Logger; | ||
import org.openstack4j.api.Builders; | ||
import org.openstack4j.model.network.AllowedAddressPair; | ||
import org.openstack4j.model.network.Port; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@Path("/openstack/neutron/ports/") | ||
@ApplicationScoped | ||
public class OpenstackNeutronPortResource { | ||
|
||
private static final Logger LOG = Logger.getLogger(OpenstackNeutronPortResource.class); | ||
|
||
private static final String URI_FORMAT = "openstack-neutron://{{camel.openstack.test.host-url}}?username=user&password=secret&project=project&operation=%s&subsystem=" | ||
+ NeutronConstants.NEUTRON_PORT_SYSTEM; | ||
|
||
private static final String NETWORK_ID = "a87cc70a-3e15-4acf-8205-9b711a3531b7"; | ||
|
||
@Inject | ||
ProducerTemplate template; | ||
|
||
@Path("/createShouldSucceed") | ||
@POST | ||
public void createShouldSucceed() { | ||
LOG.debug("Calling OpenstackNeutronPortResource.createShouldSucceed()"); | ||
|
||
Port in = Builders.port().networkId(NETWORK_ID).build(); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.CREATE); | ||
Port out = template.requestBody(uri, in, Port.class); | ||
|
||
assertNotNull(out); | ||
assertEquals(NETWORK_ID, out.getNetworkId()); | ||
assertNotNull(out.getAllowedAddressPairs()); | ||
assertEquals(1, out.getAllowedAddressPairs().size()); | ||
AllowedAddressPair allowedAddressPair = out.getAllowedAddressPairs().iterator().next(); | ||
assertNotNull(allowedAddressPair.getIpAddress()); | ||
assertNotNull(allowedAddressPair.getMacAddress()); | ||
} | ||
|
||
@Path("/getAllShouldSucceed") | ||
@POST | ||
public void getAllShouldSucceed() { | ||
LOG.debug("Calling OpenstackNeutronPortResource.getAllShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET_ALL); | ||
Port[] ports = template.requestBody(uri, null, Port[].class); | ||
|
||
assertNotNull(ports); | ||
assertEquals(2, ports.length); | ||
assertEquals(NETWORK_ID, ports[0].getNetworkId()); | ||
assertEquals("94225baa-9d3f-4b93-bf12-b41e7ce49cdb", ports[0].getId()); | ||
assertEquals(NETWORK_ID, ports[1].getNetworkId()); | ||
assertEquals("235b09e0-63c4-47f1-b221-66ba54c21760", ports[1].getId()); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
.../java/org/apache/camel/quarkus/component/openstack/it/OpenstackNeutronSubnetResource.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,66 @@ | ||
/* | ||
* 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 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.neutron.NeutronConstants; | ||
import org.jboss.logging.Logger; | ||
import org.openstack4j.model.network.Ipv6AddressMode; | ||
import org.openstack4j.model.network.Ipv6RaMode; | ||
import org.openstack4j.model.network.Subnet; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@Path("/openstack/neutron/subnets/") | ||
@ApplicationScoped | ||
public class OpenstackNeutronSubnetResource { | ||
|
||
private static final Logger LOG = Logger.getLogger(OpenstackNeutronSubnetResource.class); | ||
|
||
private static final String URI_FORMAT = "openstack-neutron://{{camel.openstack.test.host-url}}?username=user&password=secret&project=project&operation=%s&subsystem=" | ||
+ NeutronConstants.NEUTRON_SUBNETS_SYSTEM; | ||
|
||
private static final String SUBNET_NAME = "sub1"; | ||
private static final String SUBNET_ID = "3b80198d-4f7b-4f77-9ef5-774d54e17126"; | ||
|
||
@Inject | ||
ProducerTemplate template; | ||
|
||
@Path("/getShouldSucceed") | ||
@POST | ||
public void getShouldSucceed() { | ||
LOG.debug("Calling OpenstackNeutronSubnetResource.getShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET); | ||
Subnet out = template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, SUBNET_ID, Subnet.class); | ||
|
||
assertNotNull(out); | ||
assertEquals(SUBNET_NAME, out.getName()); | ||
assertEquals(Ipv6AddressMode.DHCPV6_STATEFUL, out.getIpv6AddressMode()); | ||
assertEquals(Ipv6RaMode.DHCPV6_STATEFUL, out.getIpv6RaMode()); | ||
assertNotNull(out.getDnsNames()); | ||
assertTrue(out.getDnsNames().isEmpty()); | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...ain/java/org/apache/camel/quarkus/component/openstack/it/OpenstackNovaFlavorResource.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,106 @@ | ||
/* | ||
* 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 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.nova.NovaConstants; | ||
import org.jboss.logging.Logger; | ||
import org.openstack4j.api.Builders; | ||
import org.openstack4j.model.compute.Flavor; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@Path("/openstack/nova/flavors/") | ||
@ApplicationScoped | ||
public class OpenstackNovaFlavorResource { | ||
|
||
private static final Logger LOG = Logger.getLogger(OpenstackNovaFlavorResource.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_FLAVORS; | ||
|
||
private static final String FLAVOR_ID = "1"; | ||
private static final String FLAVOR_NAME = "m1.tiny"; | ||
|
||
@Inject | ||
ProducerTemplate template; | ||
|
||
@Path("/createShouldSucceed") | ||
@POST | ||
public void createShouldSucceed() { | ||
LOG.debug("Calling OpenstackNovaFlavorResource.createShouldSucceed()"); | ||
|
||
Flavor in = Builders.flavor().name("safe_to_delete_flavor").vcpus(1).disk(2).isPublic(true).rxtxFactor(2.0f) | ||
.ephemeral(1) | ||
.ram(128).id("delete_1").swap(1).build(); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.CREATE); | ||
Flavor out = template.requestBody(uri, in, Flavor.class); | ||
|
||
assertNotNull(out); | ||
assertEquals(1, out.getVcpus()); | ||
assertEquals(2, out.getDisk()); | ||
assertEquals(FLAVOR_NAME, out.getName()); | ||
assertTrue(out.isPublic()); | ||
assertEquals(2.0f, out.getRxtxFactor()); | ||
assertEquals(1, out.getEphemeral()); | ||
assertEquals(128, out.getRam()); | ||
assertEquals(FLAVOR_ID, out.getId()); | ||
assertEquals(1, out.getSwap()); | ||
} | ||
|
||
@Path("/getShouldSucceed") | ||
@POST | ||
public void getShouldSucceed() { | ||
LOG.debug("Calling OpenstackNovaFlavorResource.getShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET); | ||
Flavor out = template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, FLAVOR_ID, Flavor.class); | ||
|
||
assertNotNull(out); | ||
assertEquals(1, out.getDisk()); | ||
assertEquals(FLAVOR_NAME, out.getName()); | ||
assertEquals(512, out.getRam()); | ||
assertTrue(out.isPublic()); | ||
assertEquals(0, out.getEphemeral()); | ||
assertFalse(out.isDisabled()); | ||
assertEquals(2.0f, out.getRxtxFactor()); | ||
assertEquals(1, out.getVcpus()); | ||
} | ||
|
||
@Path("/getAllShouldSucceed") | ||
@POST | ||
public void getAllShouldSucceed() { | ||
LOG.debug("Calling OpenstackNovaFlavorResource.getAllShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET_ALL); | ||
Flavor[] flavors = template.requestBody(uri, null, Flavor[].class); | ||
|
||
assertNotNull(flavors); | ||
assertEquals(2, flavors.length); | ||
} | ||
|
||
} |
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
38 changes: 38 additions & 0 deletions
38
...c/test/java/org/apache/camel/quarkus/component/openstack/it/OpenstackNeutronPortTest.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,38 @@ | ||
/* | ||
* 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 OpenstackNeutronPortTest { | ||
|
||
@Test | ||
public void createShouldSucceed() { | ||
post("/openstack/neutron/ports/createShouldSucceed").then().statusCode(204); | ||
} | ||
|
||
@Test | ||
public void getAllShouldSucceed() { | ||
post("/openstack/neutron/ports/getAllShouldSucceed").then().statusCode(204); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...test/java/org/apache/camel/quarkus/component/openstack/it/OpenstackNeutronSubnetTest.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,33 @@ | ||
/* | ||
* 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 OpenstackNeutronSubnetTest { | ||
|
||
@Test | ||
public void getShouldSucceed() { | ||
post("/openstack/neutron/subnets/getShouldSucceed").then().statusCode(204); | ||
} | ||
} |
Oops, something went wrong.