Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the integration tests to verify template version support in application management API #20745

Merged
merged 11 commits into from
Aug 5, 2024
Merged
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2019-2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nimbusds.oauth2.sdk.util.URLUtils;
import io.restassured.response.Response;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpStatus;
Expand All @@ -28,6 +31,7 @@
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.identity.application.mgt.ApplicationConstants;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationListItem;
import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationListResponse;

import java.io.IOException;
Expand All @@ -38,6 +42,7 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.wso2.identity.integration.test.rest.api.server.application.management.v1.Utils.assertNotBlank;
import static org.wso2.identity.integration.test.rest.api.server.application.management.v1.Utils.extractApplicationIdFromLocationHeader;
Expand All @@ -49,6 +54,8 @@ public class ApplicationManagementSuccessTest extends ApplicationManagementBaseT

private static final String MY_ACCOUNT = "My Account";
private static final String CREATED_APP_NAME = "My SAMPLE APP";
private static final String CREATED_APP_TEMPLATE_ID = "Test_template_1";
private static final String CREATED_APP_TEMPLATE_VERSION = "v1.0.0";
private String createdAppId;

@Factory(dataProvider = "restAPIUserConfigProvider")
Expand Down Expand Up @@ -111,6 +118,30 @@ public void createApplication() throws Exception {
assertNotBlank(createdAppId);
}

@Test(dependsOnMethods = {"createApplication"})
DilshanSenarath marked this conversation as resolved.
Show resolved Hide resolved
public void testGetAllApplicationsWithParams() throws IOException {

Map<String, Object> params = new HashMap<>();
params.put("attributes", "templateId,templateVersion");
Response response = getResponseOfGet(APPLICATION_MANAGEMENT_API_BASE_PATH, params);
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK);
ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory());
ApplicationListResponse listResponse = jsonWriter.readValue(response.asString(), ApplicationListResponse.class);

assertNotNull(listResponse);

// Verify that the newly created app exists and has the required properties.
Optional<ApplicationListItem> newlyCreatedAppData = listResponse.getApplications().stream()
.filter(appBasicInfo -> appBasicInfo.getName().equals(CREATED_APP_NAME)).findFirst();
Assert.assertTrue(newlyCreatedAppData.isPresent(),
"Newly Created application '" + CREATED_APP_NAME + "' is not listed by the API.");
Assert.assertEquals(newlyCreatedAppData.get().getTemplateId(), CREATED_APP_TEMPLATE_ID);
Assert.assertEquals(newlyCreatedAppData.get().getTemplateVersion(), CREATED_APP_TEMPLATE_VERSION);
}

@Test(dependsOnMethods = {"createApplication"})
public void testGetApplicationById() throws Exception {

Expand All @@ -119,7 +150,9 @@ public void testGetApplicationById() throws Exception {
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("name", equalTo(CREATED_APP_NAME));
.body("name", equalTo(CREATED_APP_NAME))
.body("templateId", equalTo(CREATED_APP_TEMPLATE_ID))
.body("templateVersion", equalTo(CREATED_APP_TEMPLATE_VERSION));
}

@Test(dependsOnMethods = {"createApplication"})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2019-2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,6 +37,8 @@ public class ApplicationPatchTest extends ApplicationManagementBaseTest {

private static final String APP_NAME = "testPatchApplication";
public static final String UPDATED_APP_NAME = "testUpdateNameApplication";
private static final String APP_TEMPLATE_ID = "Test_template_1";
private static final String APP_TEMPLATE_VERSION = "v1.0.0";
public static final String SUBJECT_CLAIM_URI = "http://wso2.org/claims/username";
private String appId;

Expand All @@ -51,6 +53,8 @@ public void testCreateApplication() throws Exception {

JSONObject createRequest = new JSONObject();
createRequest.put("name", APP_NAME);
createRequest.put("templateId", APP_TEMPLATE_ID);
createRequest.put("templateVersion", APP_TEMPLATE_VERSION);
String payload = createRequest.toString();

Response responseOfPost = getResponseOfPost(APPLICATION_MANAGEMENT_API_BASE_PATH, payload);
Expand All @@ -69,7 +73,9 @@ public void testCreateApplication() throws Exception {
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("name", equalTo(APP_NAME));
.body("name", equalTo(APP_NAME))
.body("templateId", equalTo(APP_TEMPLATE_ID))
.body("templateVersion", equalTo(APP_TEMPLATE_VERSION));
}

@Test(dependsOnMethods = "testCreateApplication")
Expand All @@ -93,11 +99,15 @@ public void testUpdateBasicInformation() throws Exception {
String description = "This is my application.";
String imageUrl = "https://localhost/image.png";
String accessUrl = "https://app.test.com/login";
String templateId = "Test_template_2";
String templateVersion = "v1.0.1";

JSONObject patchRequest = new JSONObject();
patchRequest.put("description", description);
patchRequest.put("imageUrl", imageUrl);
patchRequest.put("accessUrl", accessUrl);
patchRequest.put("templateId", templateId);
patchRequest.put("templateVersion", templateVersion);

String path = APPLICATION_MANAGEMENT_API_BASE_PATH + "/" + appId;
getResponseOfPatch(path, patchRequest.toString()).then()
Expand All @@ -107,7 +117,9 @@ public void testUpdateBasicInformation() throws Exception {
getApplication(appId).then()
.body("description", equalTo(description))
.body("imageUrl", equalTo(imageUrl))
.body("accessUrl", equalTo(accessUrl));
.body("accessUrl", equalTo(accessUrl))
.body("templateId", equalTo(templateId))
.body("templateVersion", equalTo(templateVersion));
}

@Test(dependsOnMethods = "testUpdateBasicInformation")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2019-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -72,6 +72,7 @@ public static AccessEnum fromValue(String value) {
private String self;
private AdvancedApplicationConfiguration advancedConfigurations;
private String templateId;
private String templateVersion;
private AssociatedRolesConfig associatedRoles;

/**
Expand Down Expand Up @@ -290,6 +291,25 @@ public void setTemplateId(String templateId) {
this.templateId = templateId;
}

/**
* Version of the template used to create the application.
**/
public ApplicationListItem templateVersion(String templateVersion) {

this.templateVersion = templateVersion;
return this;
}

@ApiModelProperty(example = "v1.0.0", value = "Version of the template used to create the application.")
@JsonProperty("templateVersion")
@Valid
public String getTemplateVersion() {
return templateVersion;
}
public void setTemplateVersion(String templateVersion) {
this.templateVersion = templateVersion;
}

/**
**/
public ApplicationListItem associatedRoles(AssociatedRolesConfig associatedRoles) {
Expand Down Expand Up @@ -330,12 +350,13 @@ public boolean equals(java.lang.Object o) {
Objects.equals(this.self, applicationListItem.self) &&
Objects.equals(this.advancedConfigurations, applicationListItem.advancedConfigurations) &&
Objects.equals(this.templateId, applicationListItem.templateId) &&
Objects.equals(this.templateVersion, applicationListItem.templateVersion) &&
Objects.equals(this.associatedRoles, applicationListItem.associatedRoles);
}

@Override
public int hashCode() {
return Objects.hash(id, name, description, image, accessUrl, clientId, issuer, realm, access, self, advancedConfigurations, templateId, associatedRoles);
return Objects.hash(id, name, description, image, accessUrl, clientId, issuer, realm, access, self, advancedConfigurations, templateId, templateVersion, associatedRoles);
}

@Override
Expand All @@ -356,6 +377,7 @@ public String toString() {
sb.append(" self: ").append(toIndentedString(self)).append("\n");
sb.append(" advancedConfigurations: ").append(toIndentedString(advancedConfigurations)).append("\n");
sb.append(" templateId: ").append(toIndentedString(templateId)).append("\n");
sb.append(" templateVersion: ").append(toIndentedString(templateVersion)).append("\n");
sb.append(" associatedRoles: ").append(toIndentedString(associatedRoles)).append("\n");
sb.append("}");
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -33,6 +33,7 @@ public class ApplicationPatchModel {
private String imageUrl;
private String accessUrl;
private String templateId;
private String templateVersion;
private AssociatedRolesConfig associatedRoles;
private ClaimConfiguration claimConfiguration;
private AuthenticationSequence authenticationSequence;
Expand Down Expand Up @@ -129,6 +130,25 @@ public void setTemplateId(String templateId) {
this.templateId = templateId;
}

/**
* Version of the template used to create the application.
**/
public ApplicationPatchModel templateVersion(String templateVersion) {

this.templateVersion = templateVersion;
return this;
}

@ApiModelProperty(example = "v1.0.0", value = "Version of the template used to create the application.")
@JsonProperty("templateVersion")
@Valid
public String getTemplateVersion() {
return templateVersion;
}
public void setTemplateVersion(String templateVersion) {
this.templateVersion = templateVersion;
}

/**
**/
public ApplicationPatchModel associatedRoles(AssociatedRolesConfig associatedRoles) {
Expand Down Expand Up @@ -236,6 +256,7 @@ public boolean equals(java.lang.Object o) {
Objects.equals(this.imageUrl, applicationPatchModel.imageUrl) &&
Objects.equals(this.accessUrl, applicationPatchModel.accessUrl) &&
Objects.equals(this.templateId, applicationPatchModel.templateId) &&
Objects.equals(this.templateVersion, applicationPatchModel.templateVersion) &&
Objects.equals(this.associatedRoles, applicationPatchModel.associatedRoles) &&
Objects.equals(this.claimConfiguration, applicationPatchModel.claimConfiguration) &&
Objects.equals(this.authenticationSequence, applicationPatchModel.authenticationSequence) &&
Expand All @@ -245,7 +266,7 @@ public boolean equals(java.lang.Object o) {

@Override
public int hashCode() {
return Objects.hash(name, description, imageUrl, accessUrl, templateId, associatedRoles, claimConfiguration, authenticationSequence, advancedConfigurations, provisioningConfigurations);
return Objects.hash(name, description, imageUrl, accessUrl, templateId, templateVersion, associatedRoles, claimConfiguration, authenticationSequence, advancedConfigurations, provisioningConfigurations);
}

@Override
Expand All @@ -259,6 +280,7 @@ public String toString() {
sb.append(" imageUrl: ").append(toIndentedString(imageUrl)).append("\n");
sb.append(" accessUrl: ").append(toIndentedString(accessUrl)).append("\n");
sb.append(" templateId: ").append(toIndentedString(templateId)).append("\n");
sb.append(" templateVersion: ").append(toIndentedString(templateVersion)).append("\n");
sb.append(" associatedRoles: ").append(toIndentedString(associatedRoles)).append("\n");
sb.append(" claimConfiguration: ").append(toIndentedString(claimConfiguration)).append("\n");
sb.append(" authenticationSequence: ").append(toIndentedString(authenticationSequence)).append("\n");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -39,6 +39,7 @@ public class ApplicationResponseModel {
private String issuer;
private String realm;
private String templateId;
private String templateVersion;
private Boolean isManagementApp;
private Boolean isB2BSelfServiceApp;
private Boolean applicationEnabled;
Expand Down Expand Up @@ -265,6 +266,25 @@ public void setTemplateId(String templateId) {
this.templateId = templateId;
}

/**
* Version of the template used to create the application.
**/
public ApplicationResponseModel templateVersion(String templateVersion) {

this.templateVersion = templateVersion;
return this;
}

@ApiModelProperty(example = "v1.0.0", value = "Version of the template used to create the application.")
@JsonProperty("templateVersion")
@Valid
public String getTemplateVersion() {
return templateVersion;
}
public void setTemplateVersion(String templateVersion) {
this.templateVersion = templateVersion;
}

/**
* Decides whether the application used to access System APIs
**/
Expand Down Expand Up @@ -470,6 +490,7 @@ public boolean equals(Object o) {
Objects.equals(this.issuer, applicationResponseModel.issuer) &&
Objects.equals(this.realm, applicationResponseModel.realm) &&
Objects.equals(this.templateId, applicationResponseModel.templateId) &&
Objects.equals(this.templateVersion, applicationResponseModel.templateVersion) &&
Objects.equals(this.isManagementApp, applicationResponseModel.isManagementApp) &&
Objects.equals(this.isB2BSelfServiceApp, applicationResponseModel.isB2BSelfServiceApp) &&
Objects.equals(this.applicationEnabled, applicationResponseModel.applicationEnabled) &&
Expand All @@ -484,7 +505,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(id, name, description, imageUrl, accessUrl, logoutReturnUrl, clientId, issuer, realm, templateId, isManagementApp, isB2BSelfServiceApp, applicationEnabled, associatedRoles, claimConfiguration, inboundProtocols, authenticationSequence, advancedConfigurations, provisioningConfigurations, access);
return Objects.hash(id, name, description, imageUrl, accessUrl, logoutReturnUrl, clientId, issuer, realm, templateId, templateVersion, isManagementApp, isB2BSelfServiceApp, applicationEnabled, associatedRoles, claimConfiguration, inboundProtocols, authenticationSequence, advancedConfigurations, provisioningConfigurations, access);
}

@Override
Expand All @@ -502,6 +523,7 @@ public String toString() {
sb.append(" issuer: ").append(toIndentedString(issuer)).append("\n");
sb.append(" realm: ").append(toIndentedString(realm)).append("\n");
sb.append(" templateId: ").append(toIndentedString(templateId)).append("\n");
sb.append(" templateVersion: ").append(toIndentedString(templateVersion)).append("\n");
sb.append(" isManagementApp: ").append(toIndentedString(isManagementApp)).append("\n");
sb.append(" isB2BSelfServiceApp: ").append(toIndentedString(isB2BSelfServiceApp)).append("\n");
sb.append(" applicationEnabled: ").append(toIndentedString(applicationEnabled)).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
"name": "My SAMPLE APP",
"description": "my application 2",
"imageUrl": "https://localhost/image",
"accessUrl": "https://localhost/accessUrl"
"accessUrl": "https://localhost/accessUrl",
"templateId": "Test_template_1",
"templateVersion": "v1.0.0"
}
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2014, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
~ Copyright (c) 2014-2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -2272,7 +2272,7 @@
<properties>

<!--Carbon Identity Framework Version-->
<carbon.identity.framework.version>7.3.56</carbon.identity.framework.version>
<carbon.identity.framework.version>7.3.57</carbon.identity.framework.version>
<carbon.identity.framework.version.range>[5.14.67, 8.0.0)</carbon.identity.framework.version.range>

<!--SAML Common Utils Version-->
Expand Down Expand Up @@ -2385,7 +2385,7 @@
<!-- Identity REST API feature -->
<identity.api.dispatcher.version>2.0.17</identity.api.dispatcher.version>
<identity.user.api.version>1.3.38</identity.user.api.version>
<identity.server.api.version>1.2.212</identity.server.api.version>
<identity.server.api.version>1.2.213</identity.server.api.version>

<identity.agent.sso.version>5.5.9</identity.agent.sso.version>
<identity.tool.samlsso.validator.version>5.5.8</identity.tool.samlsso.validator.version>
Expand Down