|
8 | 8 | import org.testng.annotations.BeforeClass; |
9 | 9 | import org.testng.annotations.Test; |
10 | 10 |
|
| 11 | +import com.axway.apim.lib.error.AppException; |
| 12 | +import com.axway.apim.lib.error.ErrorCode; |
| 13 | + |
11 | 14 | public class APIImportAppTest extends WiremockWrapper { |
12 | 15 |
|
13 | 16 | @BeforeClass |
@@ -59,4 +62,59 @@ public void testEmptyPassword() throws Exception { |
59 | 62 | Assert.assertEquals("",desiredAPI.getAuthenticationProfiles().get(0).getParameters().get("password")); |
60 | 63 |
|
61 | 64 | } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void safeUpdateAllowsSameName() throws AppException { |
| 68 | + APIImportApp app = new APIImportApp(); |
| 69 | + APIImportParams params = new APIImportParams(); |
| 70 | + params.setSafeUpdate(true); |
| 71 | + |
| 72 | + API actualApi = new API(); |
| 73 | + actualApi.setId("actual-id"); |
| 74 | + actualApi.setName("Order API"); |
| 75 | + |
| 76 | + API desiredApi = new API(); |
| 77 | + desiredApi.setId("desired-id"); |
| 78 | + desiredApi.setName("Order API"); |
| 79 | + desiredApi.setPath("/api/orders/v1"); |
| 80 | + |
| 81 | + app.validateSafeUpdate(actualApi, desiredApi, params); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void safeUpdateAllowsNameMismatchWhenApiIdMatches() throws AppException { |
| 86 | + APIImportApp app = new APIImportApp(); |
| 87 | + APIImportParams params = new APIImportParams(); |
| 88 | + params.setSafeUpdate(true); |
| 89 | + |
| 90 | + API actualApi = new API(); |
| 91 | + actualApi.setId("same-id"); |
| 92 | + actualApi.setName("Order API"); |
| 93 | + |
| 94 | + API desiredApi = new API(); |
| 95 | + desiredApi.setId("same-id"); |
| 96 | + desiredApi.setName("Inventory API"); |
| 97 | + desiredApi.setPath("/api/orders/v1"); |
| 98 | + |
| 99 | + app.validateSafeUpdate(actualApi, desiredApi, params); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void safeUpdateBlocksNameMismatchForSamePath() { |
| 104 | + APIImportApp app = new APIImportApp(); |
| 105 | + APIImportParams params = new APIImportParams(); |
| 106 | + params.setSafeUpdate(true); |
| 107 | + |
| 108 | + API actualApi = new API(); |
| 109 | + actualApi.setId("actual-id"); |
| 110 | + actualApi.setName("Order API"); |
| 111 | + |
| 112 | + API desiredApi = new API(); |
| 113 | + desiredApi.setId("different-id"); |
| 114 | + desiredApi.setName("Inventory API"); |
| 115 | + desiredApi.setPath("/api/orders/v1"); |
| 116 | + |
| 117 | + AppException exception = Assert.expectThrows(AppException.class, () -> app.validateSafeUpdate(actualApi, desiredApi, params)); |
| 118 | + Assert.assertEquals(exception.getError(), ErrorCode.API_PATH_IN_USE_BY_DIFFERENT_API); |
| 119 | + } |
62 | 120 | } |
0 commit comments