-
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 keystone tests #1943
- Loading branch information
1 parent
1e75c0c
commit 5cfe78c
Showing
39 changed files
with
1,533 additions
and
0 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
...java/org/apache/camel/quarkus/component/openstack/it/OpenstackKeystoneDomainResource.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 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.keystone.KeystoneConstants; | ||
import org.jboss.logging.Logger; | ||
import org.openstack4j.api.Builders; | ||
import org.openstack4j.model.identity.v3.Domain; | ||
|
||
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/keystone/domains/") | ||
@ApplicationScoped | ||
public class OpenstackKeystoneDomainResource { | ||
|
||
private static final Logger LOG = Logger.getLogger(OpenstackKeystoneDomainResource.class); | ||
|
||
private static final String URI_FORMAT = "openstack-keystone://{{camel.openstack.test.host-url}}?username=user&password=secret&project=project&operation=%s&subsystem=" | ||
+ KeystoneConstants.DOMAINS; | ||
|
||
private static final String DOMAIN_NAME = "Domain_CRUD"; | ||
private static final String DOMAIN_ID = "98c110ae41c249189c9d5c25d8377b65"; | ||
private static final String DOMAIN_DESCRIPTION = "Domain used for CRUD tests"; | ||
private static final String DOMAIN_DESCRIPTION_UPDATED = "An updated domain used for CRUD tests"; | ||
|
||
@Inject | ||
ProducerTemplate template; | ||
|
||
@Path("/createShouldSucceed") | ||
@POST | ||
public void createShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneDomainResource.createShouldSucceed()"); | ||
|
||
Domain in = Builders.domain().name(DOMAIN_NAME).description(DOMAIN_DESCRIPTION).enabled(true).build(); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.CREATE); | ||
Domain out = template.requestBody(uri, in, Domain.class); | ||
|
||
assertNotNull(out); | ||
assertEquals(DOMAIN_NAME, out.getName()); | ||
assertEquals(DOMAIN_ID, out.getId()); | ||
assertEquals(DOMAIN_DESCRIPTION, out.getDescription()); | ||
} | ||
|
||
@Path("/getShouldSucceed") | ||
@POST | ||
public void getShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneDomainResource.getShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET); | ||
Domain out = template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, DOMAIN_ID, Domain.class); | ||
|
||
assertNotNull(out); | ||
assertEquals(DOMAIN_NAME, out.getName()); | ||
assertEquals(DOMAIN_ID, out.getId()); | ||
assertEquals(DOMAIN_DESCRIPTION, out.getDescription()); | ||
assertFalse(out.isEnabled()); | ||
} | ||
|
||
@Path("/getAllShouldSucceed") | ||
@POST | ||
public void getAllShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneDomainResource.getAllShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET_ALL); | ||
Domain[] domains = template.requestBody(uri, null, Domain[].class); | ||
|
||
assertEquals(1, domains.length); | ||
assertEquals("default", domains[0].getId()); | ||
assertNotNull(domains[0].getOptions()); | ||
assertTrue(domains[0].getOptions().isEmpty()); | ||
} | ||
|
||
@Path("/updateShouldSucceed") | ||
@POST | ||
public void updateShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneDomainResource.updateShouldSucceed()"); | ||
|
||
Domain in = Builders.domain().name(DOMAIN_NAME).description(DOMAIN_DESCRIPTION_UPDATED).id(DOMAIN_ID).build(); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.UPDATE); | ||
Domain out = template.requestBody(uri, in, Domain.class); | ||
|
||
assertNotNull(out); | ||
assertEquals(DOMAIN_NAME, out.getName()); | ||
assertEquals(DOMAIN_ID, out.getId()); | ||
assertEquals(DOMAIN_DESCRIPTION_UPDATED, out.getDescription()); | ||
} | ||
|
||
@Path("/deleteShouldSucceed") | ||
@POST | ||
public void deleteShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneDomainResource.deleteShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.DELETE); | ||
template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, DOMAIN_ID); | ||
} | ||
} |
169 changes: 169 additions & 0 deletions
169
.../java/org/apache/camel/quarkus/component/openstack/it/OpenstackKeystoneGroupResource.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,169 @@ | ||
/* | ||
* 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.keystone.KeystoneConstants; | ||
import org.jboss.logging.Logger; | ||
import org.openstack4j.api.Builders; | ||
import org.openstack4j.model.identity.v3.Group; | ||
|
||
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/keystone/groups/") | ||
@ApplicationScoped | ||
public class OpenstackKeystoneGroupResource { | ||
|
||
private static final Logger LOG = Logger.getLogger(OpenstackKeystoneGroupResource.class); | ||
|
||
private static final String URI_FORMAT = "openstack-keystone://{{camel.openstack.test.host-url}}?username=user&password=secret&project=project&operation=%s&subsystem=" | ||
+ KeystoneConstants.GROUPS; | ||
|
||
private static final String GROUP_NAME = "GROUP_CRUD"; | ||
private static final String GROUP_ID = "c0d675eac29945ad9dfd08aa1bb75751"; | ||
private static final String GROUP_DOMAIN_ID = "default"; | ||
private static final String GROUP_DESCRIPTION = "Group used for CRUD tests"; | ||
private static final String GROUP_DESCRIPTION_UPDATED = "An updated group used for CRUD tests"; | ||
|
||
@Inject | ||
ProducerTemplate template; | ||
|
||
@Path("/createShouldSucceed") | ||
@POST | ||
public void createShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneGroupResource.createShouldSucceed()"); | ||
|
||
Group in = Builders.group().name(GROUP_NAME).description(GROUP_DESCRIPTION).domainId(GROUP_DOMAIN_ID).build(); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.CREATE); | ||
Group out = template.requestBody(uri, in, Group.class); | ||
|
||
assertNotNull(out); | ||
assertEquals(GROUP_NAME, out.getName()); | ||
assertEquals(GROUP_DOMAIN_ID, out.getDomainId()); | ||
assertEquals(GROUP_DESCRIPTION, out.getDescription()); | ||
} | ||
|
||
@Path("/getShouldSucceed") | ||
@POST | ||
public void getShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneGroupResource.getShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET); | ||
Group out = template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, GROUP_ID, Group.class); | ||
|
||
assertNotNull(out); | ||
assertEquals(GROUP_NAME, out.getName()); | ||
assertEquals(GROUP_ID, out.getId()); | ||
assertEquals(GROUP_DOMAIN_ID, out.getDomainId()); | ||
assertEquals(GROUP_DESCRIPTION, out.getDescription()); | ||
} | ||
|
||
@Path("/getAllShouldSucceed") | ||
@POST | ||
public void getAllShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneGroupResource.getAllShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET_ALL); | ||
Group[] groups = template.requestBody(uri, null, Group[].class); | ||
|
||
assertEquals(5, groups.length); | ||
|
||
assertEquals("7261c982051c4080a69a52117a861d64", groups[0].getId()); | ||
assertEquals("default", groups[1].getDomainId()); | ||
assertEquals("Group for CRUD tests", groups[2].getDescription()); | ||
assertEquals("role_crud_group", groups[3].getName()); | ||
assertNotNull(groups[4].getLinks()); | ||
assertTrue(groups[4].getLinks().containsKey("self")); | ||
} | ||
|
||
@Path("/updateShouldSucceed") | ||
@POST | ||
public void updateShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneGroupResource.updateShouldSucceed()"); | ||
|
||
Group in = Builders.group().id(GROUP_ID).description(GROUP_DESCRIPTION_UPDATED).build(); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.UPDATE); | ||
Group out = template.requestBody(uri, in, Group.class); | ||
|
||
assertNotNull(out); | ||
assertEquals(GROUP_NAME, out.getName()); | ||
assertEquals(GROUP_ID, out.getId()); | ||
assertEquals(GROUP_DESCRIPTION_UPDATED, out.getDescription()); | ||
} | ||
|
||
@Path("/deleteShouldSucceed") | ||
@POST | ||
public void deleteShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneGroupResource.deleteShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.DELETE); | ||
template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, GROUP_ID); | ||
} | ||
|
||
@Path("/addUserToGroupShouldSucceed") | ||
@POST | ||
public void addUserToGroupShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneGroupResource.addUserToGroupShouldSucceed()"); | ||
|
||
Map<String, Object> headers = new HashMap<>(); | ||
headers.put(KeystoneConstants.USER_ID, "d599b83141fc47bc9c25e89267aa27c4"); | ||
headers.put(KeystoneConstants.GROUP_ID, "851398fccda34f208e1839ebbc1251d1"); | ||
|
||
String uri = String.format(URI_FORMAT, KeystoneConstants.ADD_USER_TO_GROUP); | ||
template.requestBodyAndHeaders(uri, null, headers, Group.class); | ||
} | ||
|
||
@Path("/checkUserGroupShouldSucceed") | ||
@POST | ||
public void checkUserGroupShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneGroupResource.checkUserGroupShouldSucceed()"); | ||
|
||
Map<String, Object> headers = new HashMap<>(); | ||
headers.put(KeystoneConstants.USER_ID, "d599b83141fc47bc9c25e89267aa27c4"); | ||
headers.put(KeystoneConstants.GROUP_ID, "851398fccda34f208e1839ebbc1251d1"); | ||
|
||
String uri = String.format(URI_FORMAT, KeystoneConstants.CHECK_GROUP_USER); | ||
boolean userInGroup = template.requestBodyAndHeaders(uri, null, headers, Boolean.class); | ||
assertTrue(userInGroup); | ||
} | ||
|
||
@Path("/removeUserFromGroupShouldSucceed") | ||
@POST | ||
public void removeUserFromGroupShouldSucceed() { | ||
LOG.debug("Calling OpenstackKeystoneGroupResource.removeUserFromGroupShouldSucceed()"); | ||
|
||
Map<String, Object> headers = new HashMap<>(); | ||
headers.put(KeystoneConstants.USER_ID, "d599b83141fc47bc9c25e89267aa27c4"); | ||
headers.put(KeystoneConstants.GROUP_ID, "851398fccda34f208e1839ebbc1251d1"); | ||
|
||
String uri = String.format(URI_FORMAT, KeystoneConstants.REMOVE_USER_FROM_GROUP); | ||
template.requestBodyAndHeaders(uri, null, headers); | ||
} | ||
} |
Oops, something went wrong.