Skip to content

Commit

Permalink
Fix issue 390
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Jul 11, 2023
1 parent 9113793 commit ac25d9c
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.axway.apim.api.model;

import com.axway.apim.lib.utils.Utils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

Expand Down Expand Up @@ -126,18 +128,23 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
APIMethod apiMethod = (APIMethod) o;
if (name.equals(apiMethod.name) && summary.equals(apiMethod.summary) && descriptionType.equals(apiMethod.descriptionType)) {
boolean flag = tags == null && apiMethod.tags == null;
if (tags != null && apiMethod.tags != null) {
flag = tags.equals(apiMethod.tags);
if (name.equals(apiMethod.name) && descriptionType.equals(apiMethod.descriptionType)) {
if (!Utils.equalsTagMap(tags, apiMethod.tags)) {
return false;
}
if (descriptionType.equals("manual") && descriptionManual.equals(apiMethod.descriptionManual)) {
flag = true;
} else if (descriptionType.equals("url") && descriptionUrl.equals(apiMethod.descriptionUrl)) {
flag = true;
} else if (descriptionType.equals("markdown") && descriptionMarkdown.equals(apiMethod.descriptionMarkdown)) {
flag = true;
// Fix defect https://github.com/Axway-API-Management-Plus/apim-cli/issues/390
if (!StringUtils.equals(summary, apiMethod.summary)) {
return false;
}
boolean flag = false;
if (descriptionType.equals("manual") && StringUtils.equals(descriptionManual, apiMethod.descriptionManual)) {
flag = true;
} else if (descriptionType.equals("url") && StringUtils.equals(descriptionUrl, apiMethod.descriptionUrl)) {
flag = true;
} else if (descriptionType.equals("markdown") && StringUtils.equals(descriptionMarkdown, apiMethod.descriptionMarkdown)) {
flag = true;
}else if (descriptionType.equals("original"))
flag = true;
return flag;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.time.ZoneId;
import java.util.*;

import com.axway.apim.api.model.TagMap;
import com.axway.apim.lib.utils.rest.Console;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringSubstitutor;
Expand Down Expand Up @@ -370,4 +371,18 @@ public static String createFileName(String host, String stage, String prefix) th
}
return prefix + host + "_" + APIManagerAdapter.getCurrentUser().getLoginName() + "_" + dateTime + ".csv";
}

public static boolean equalsTagMap(TagMap source, TagMap target) {
if (source == target) return true;
if( source == null || target == null)
return false;
if (source.size() != target.size()) return false;
for (String tagName : target.keySet()) {
if (!source.containsKey(tagName)) return false;
String[] myTags = target.get(tagName);
String[] otherTags = source.get(tagName);
if (!Objects.deepEquals(myTags, otherTags)) return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void createConnection(URI uri) throws AppException {
// We have make sure, that cookies are correctly parsed!
CoreParameters params = CoreParameters.getInstance();
int timeout = params.getTimeout();
LOG.debug("API Manager CLI timeout : {}", timeout);
LOG.debug("API Manager CLI http client timeout : {}", timeout);
RequestConfig.Builder defaultRequestConfig = RequestConfig.custom()
.setConnectTimeout(timeout)
.setSocketTimeout(timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,87 @@ public void testAPIMethodsWithDiffTagsAndUrlDesc() throws JsonProcessingExceptio
Assert.assertTrue(Utils.compareValues(apiMethods, apiMethodsDesired));

}

@Test
public void testAPIMethodsWithNoSummary() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
String actual = "[{\n" +
" \"name\": \"updateUser\",\n" +
" \"descriptionType\": \"original\"\n" +
" }]";
TypeReference<List<APIMethod>> apiMethodsTypeRef = new TypeReference<List<APIMethod>>() {};
List<APIMethod> apiMethods = objectMapper.readValue(actual, apiMethodsTypeRef);

String desired = "[{\n" +
" \"name\": \"updateUser\",\n" +
" \"descriptionType\": \"original\"\n" +
" }]";
List<APIMethod> apiMethodsDesired = objectMapper.readValue(desired, apiMethodsTypeRef);
Assert.assertTrue(Utils.compareValues(apiMethods, apiMethodsDesired));
//Assert.assertTrue(Utils.areEqualIgnoringOrder(apiMethods, apiMethodsDesired, new APIMethodByName()));

}


@Test
public void testAPIMethodsWithSummary() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
String actual = "[{\n" +
" \"name\": \"updateUser\",\n" +
" \"summary\": \"Update user\",\n" +
" \"descriptionType\": \"original\"\n" +
" }]";
TypeReference<List<APIMethod>> apiMethodsTypeRef = new TypeReference<List<APIMethod>>() {};
List<APIMethod> apiMethods = objectMapper.readValue(actual, apiMethodsTypeRef);

String desired = "[{\n" +
" \"name\": \"updateUser\",\n" +
" \"summary\": \"Update user\",\n" +
" \"descriptionType\": \"original\"\n" +
" }]";
List<APIMethod> apiMethodsDesired = objectMapper.readValue(desired, apiMethodsTypeRef);
Assert.assertTrue(Utils.compareValues(apiMethods, apiMethodsDesired));
//Assert.assertTrue(Utils.areEqualIgnoringOrder(apiMethods, apiMethodsDesired, new APIMethodByName()));

}

@Test
public void testAPIMethodsWithSourceSummary() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
String actual = "[{\n" +
" \"name\": \"updateUser\",\n" +
" \"summary\": \"Update user\",\n" +
" \"descriptionType\": \"original\"\n" +
" }]";
TypeReference<List<APIMethod>> apiMethodsTypeRef = new TypeReference<List<APIMethod>>() {};
List<APIMethod> apiMethods = objectMapper.readValue(actual, apiMethodsTypeRef);

String desired = "[{\n" +
" \"name\": \"updateUser\",\n" +
" \"descriptionType\": \"original\"\n" +
" }]";
List<APIMethod> apiMethodsDesired = objectMapper.readValue(desired, apiMethodsTypeRef);
Assert.assertFalse(Utils.compareValues(apiMethods, apiMethodsDesired));

}

@Test
public void testAPIMethodsWithTargetSummary() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
String actual = "[{\n" +
" \"name\": \"updateUser\",\n" +
" \"descriptionType\": \"original\"\n" +
" }]";
TypeReference<List<APIMethod>> apiMethodsTypeRef = new TypeReference<List<APIMethod>>() {};
List<APIMethod> apiMethods = objectMapper.readValue(actual, apiMethodsTypeRef);

String desired = "[{\n" +
" \"name\": \"updateUser\",\n" +
" \"summary\": \"Update user\",\n" +
" \"descriptionType\": \"original\"\n" +
" }]";
List<APIMethod> apiMethodsDesired = objectMapper.readValue(desired, apiMethodsTypeRef);
Assert.assertFalse(Utils.compareValues(apiMethods, apiMethodsDesired));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.axway.apim.api.API;
import com.axway.apim.api.model.APIMethod;
import com.axway.apim.api.model.TagMap;
import com.axway.apim.lib.CoreParameters;
import com.axway.apim.lib.error.AppException;
import com.axway.apim.lib.utils.Utils;
Expand Down Expand Up @@ -297,4 +298,43 @@ public void testAskYesNo() throws IOException {
Assert.assertFalse(Utils.askYesNo("Publish or not"));
in.close();
}

@Test void equalsTagMapNull(){
Assert.assertTrue(Utils.equalsTagMap(null, null));
}


@Test void equalsTagMap(){
TagMap source = new TagMap();
source.put("stage", new String[]{"dev"});

TagMap target = new TagMap();
target.put("stage", new String[]{"dev"});
Assert.assertTrue(Utils.equalsTagMap(source, target));
}

@Test void NotEqualsTagMap(){
TagMap source = new TagMap();
source.put("stage", new String[]{"dev"});

TagMap target = new TagMap();
target.put("stage", new String[]{"prod"});
Assert.assertFalse(Utils.equalsTagMap(source, target));
}

@Test void NotEqualsTagMapSourceNull(){


TagMap target = new TagMap();
target.put("stage", new String[]{"prod"});
Assert.assertFalse(Utils.equalsTagMap(null, target));
}

@Test void NotEqualsTagMapTargetNull(){
TagMap source = new TagMap();
source.put("stage", new String[]{"dev"});

Assert.assertFalse(Utils.equalsTagMap(source, null));
}

}

0 comments on commit ac25d9c

Please sign in to comment.