Tests for OpenStack4j using TestNG test framework and an web server to mock server-client communication.
Tests are created in the folder corresponding to the OpenStack service. The following code shows a simple example.
@Test(groups = "idV3", suiteName = "Identity/V3/Keystone")
public class KeystoneCredentialServiceTests extends AbstractTest {
# Mocking response using json. Define path to file in /resources folder.
private static final String JSON_CREDENTIALS_UPDATE = "/identity/v3/credentials_update_response.json";
# Initialize corresponding service
@Override
protected Service service() {
return Service.IDENTITY;
}
// ------------ Tests ------------
public void credentials_update_Test() throws Exception {
# respond to subsequent request with the JSON
respondWith(JSON_CREDENTIALS_UPDATE);
Credential updatedCredential = osv3().identity().credentials().update(Builders.credential()
.id(CREDENTIAL_CRUD_ID)
.blob(CREDENTIAL_CRUD_BLOB_UPDATE)
.build());
assertEquals(updatedCredential.getId(), CREDENTIAL_CRUD_ID);
assertEquals(updatedCredential.getBlob(), CREDENTIAL_CRUD_BLOB_UPDATE);
assertEquals(updatedCredential.getUserId(), CREDENTIAL_CRUD_USER_ID);
assertEquals(updatedCredential.getProjectId(), CREDENTIAL_CRUD_PROJECT_ID);
}
}
core-test
module are executed in the test phase via mvn clean test
(or any phase later).OpenStack services require an endpoint in the service catalog of a access object (Keystone v2) or of token (Keystone v3). Since the initial authentication request and its response are mocked, the endpoints have to added manually to the corresponding files. The following fragments might be helpful.
#####Keystone V2:
# Add to service catalog in /resources/idenity/v2/access.json
{
"endpoints": [
{
"adminURL": "http:\/\/127.0.0.1:8774\/v2\/b80f8d4e28b74188858b654cb1fccf7d",
"region": "RegionOne",
"internalURL": "http:\/\/127.0.0.1:8774\/v2\/b80f8d4e28b74188858b654cb1fccf7d",
"id": "3d44054fe0ec440e9d4641a7219002dd",
"publicURL": "http:\/\/127.0.0.1:8774\/v2\/b80f8d4e28b74188858b654cb1fccf7d"
}
],
"endpoints_links": [],
"type": "compute",
"name": "nova"
}
#####Keystone V3:
# Add to catalog in /resources/idenity/v3/auth_v3_project.json
{
"endpoints": [
{
"region_id": "RegionOne",
"url": "http://127.0.0.1:<port>",
"region": "RegionOne",
"interface": "public",
"id": "<id>"
},
{
"region_id": "RegionOne",
"url": "http://127.0.0.1:<port>",
"region": "RegionOne",
"interface": "admin",
"id": "<id>"
},
{
"region_id": "RegionOne",
"url": "http://127.0.0.1:<port>",
"region": "RegionOne",
"interface": "internal",
"id": "<id>"
}
],
"type": "<type>",
"id": "<id>",
"name": "<name>"
}
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )