|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com). |
| 3 | + * |
| 4 | + * WSO2 LLC. licenses this file to you under the Apache License, |
| 5 | + * Version 2.0 (the "License"); you may not use this file except |
| 6 | + * in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, |
| 12 | + * software distributed under the License is distributed on an |
| 13 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | + * KIND, either express or implied. See the License for the |
| 15 | + * specific language governing permissions and limitations |
| 16 | + * under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.wso2.carbon.apimgt.rest.api.admin.v1.impl; |
| 20 | + |
| 21 | +import org.junit.Before; |
| 22 | +import org.junit.Test; |
| 23 | +import org.wso2.carbon.apimgt.api.model.API; |
| 24 | +import org.wso2.carbon.apimgt.api.model.APIIdentifier; |
| 25 | +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApiResultDTO; |
| 26 | +import org.wso2.carbon.apimgt.rest.api.admin.v1.utils.mappings.APIInfoMappingUtil; |
| 27 | + |
| 28 | +public class APIInfoMappingUtilTest { |
| 29 | + private API api1; |
| 30 | + private API api2; |
| 31 | + private API api3; |
| 32 | + private API api1tenant; |
| 33 | + private API api2tenant; |
| 34 | + private API api3tenant; |
| 35 | + private APIIdentifier apiId; |
| 36 | + |
| 37 | + @Before |
| 38 | + public void setUp() { |
| 39 | + apiId = new APIIdentifier("apicreator", "GoogleAPI", "1.0.0"); |
| 40 | + api1 = new API(apiId); |
| 41 | + api1.setUuid("b95ab4d5-c83e-4895-afb8-e1853602e88f"); |
| 42 | + |
| 43 | + apiId = new APIIdentifier("admin", "TwitterAPI", "1.0.0"); |
| 44 | + api2 = new API(apiId); |
| 45 | + api2.setUuid("16d5b419-cf5b-478a-ba05-1973264ffedf"); |
| 46 | + |
| 47 | + apiId = new APIIdentifier("admin", "FacebookAPI", "1.0.0"); |
| 48 | + api3 = new API(apiId); |
| 49 | + api3.setUuid("0db65e3c-ef12-43e2-8626-4fa4a663ae60"); |
| 50 | + |
| 51 | + apiId = new APIIdentifier("apicreator-AT-pizzashack.com", "GoogleAPI", "1.0.0"); |
| 52 | + api1tenant = new API(apiId); |
| 53 | + api1tenant.setUuid("b95ab4d5-c83e-4895-afb8-e1853602e88f"); |
| 54 | + |
| 55 | + apiId = new APIIdentifier("admin-AT-pizzashack.com", "TwitterAPI", "1.0.0"); |
| 56 | + api2tenant = new API(apiId); |
| 57 | + api2tenant.setUuid("16d5b419-cf5b-478a-ba05-1973264ffedf"); |
| 58 | + |
| 59 | + apiId = new APIIdentifier("admin-AT-pizzashack.com", "FacebookAPI", "1.0.0"); |
| 60 | + api3tenant = new API(apiId); |
| 61 | + api3tenant.setUuid("0db65e3c-ef12-43e2-8626-4fa4a663ae60"); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void testFromAPIToAPIResultDTO() { |
| 66 | + ApiResultDTO apiResultDTO1 = APIInfoMappingUtil.fromAPIToAPIResultDTO(api1); |
| 67 | + ApiResultDTO apiResultDTO2 = APIInfoMappingUtil.fromAPIToAPIResultDTO(api2); |
| 68 | + ApiResultDTO apiResultDTO3 = APIInfoMappingUtil.fromAPIToAPIResultDTO(api3); |
| 69 | + |
| 70 | + assert(apiResultDTO1.getId().equals("b95ab4d5-c83e-4895-afb8-e1853602e88f")); |
| 71 | + assert(apiResultDTO1.getName().equals("GoogleAPI")); |
| 72 | + assert(apiResultDTO1.getVersion().equals("1.0.0")); |
| 73 | + assert(apiResultDTO1.getProvider().equals("apicreator")); |
| 74 | + |
| 75 | + assert(apiResultDTO2.getId().equals("16d5b419-cf5b-478a-ba05-1973264ffedf")); |
| 76 | + assert(apiResultDTO2.getName().equals("TwitterAPI")); |
| 77 | + assert(apiResultDTO2.getVersion().equals("1.0.0")); |
| 78 | + assert(apiResultDTO2.getProvider().equals("admin")); |
| 79 | + |
| 80 | + assert(apiResultDTO3.getId().equals("0db65e3c-ef12-43e2-8626-4fa4a663ae60")); |
| 81 | + assert(apiResultDTO3.getName().equals("FacebookAPI")); |
| 82 | + assert(apiResultDTO3.getVersion().equals("1.0.0")); |
| 83 | + assert(apiResultDTO3.getProvider().equals("admin")); |
| 84 | + |
| 85 | + ApiResultDTO apiResultDTO1tenant = APIInfoMappingUtil.fromAPIToAPIResultDTO(api1tenant); |
| 86 | + ApiResultDTO apiResultDTO2tenant = APIInfoMappingUtil.fromAPIToAPIResultDTO(api2tenant); |
| 87 | + ApiResultDTO apiResultDTO3tenant = APIInfoMappingUtil.fromAPIToAPIResultDTO(api3tenant); |
| 88 | + |
| 89 | + assert(apiResultDTO1tenant.getId().equals("b95ab4d5-c83e-4895-afb8-e1853602e88f")); |
| 90 | + assert(apiResultDTO1tenant.getName().equals("GoogleAPI")); |
| 91 | + assert(apiResultDTO1tenant.getVersion().equals("1.0.0")); |
| 92 | + assert(apiResultDTO1tenant.getProvider().equals("apicreator@pizzashack.com")); |
| 93 | + |
| 94 | + assert(apiResultDTO2tenant.getId().equals("16d5b419-cf5b-478a-ba05-1973264ffedf")); |
| 95 | + assert(apiResultDTO2tenant.getName().equals("TwitterAPI")); |
| 96 | + assert(apiResultDTO2tenant.getVersion().equals("1.0.0")); |
| 97 | + assert(apiResultDTO2tenant.getProvider().equals("admin@pizzashack.com")); |
| 98 | + |
| 99 | + assert(apiResultDTO3tenant.getId().equals("0db65e3c-ef12-43e2-8626-4fa4a663ae60")); |
| 100 | + assert(apiResultDTO3tenant.getName().equals("FacebookAPI")); |
| 101 | + assert(apiResultDTO3tenant.getVersion().equals("1.0.0")); |
| 102 | + assert(apiResultDTO3tenant.getProvider().equals("admin@pizzashack.com")); |
| 103 | + } |
| 104 | +} |
0 commit comments