Amazon and eBay Buy/Sell APIs
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package de.rwu.easydrop.api.client;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
class AmazonSellerTest {
|
||||
private AmazonSeller demoSeller;
|
||||
|
||||
private static String demoApiKey = "my-api-key";
|
||||
private static String demoApiUrl = "https://www.example.com/api";
|
||||
private static String demoDataTarget = "Amazon";
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
demoSeller = new AmazonSeller(
|
||||
demoApiUrl,
|
||||
demoApiKey);
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructor() {
|
||||
// Assert
|
||||
try {
|
||||
Field baseUrlField = AmazonSeller.class.getDeclaredField("baseUrl");
|
||||
baseUrlField.setAccessible(true);
|
||||
Assertions.assertEquals(demoApiUrl, baseUrlField.get(demoSeller));
|
||||
|
||||
Field apiKeyField = AmazonSeller.class.getDeclaredField("apiKey");
|
||||
apiKeyField.setAccessible(true);
|
||||
Assertions.assertEquals(demoApiKey, apiKeyField.get(demoSeller));
|
||||
} catch (NoSuchFieldException e) {
|
||||
Assertions.fail();
|
||||
} catch (IllegalAccessException e) {
|
||||
Assertions.fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateApiUrl() throws MalformedURLException {
|
||||
// Test case 1
|
||||
String productId1 = "12345";
|
||||
URL expectedUrl1 = new URL(
|
||||
"https://www.example.com/api/products/2020-08-26/products/"
|
||||
+ productId1
|
||||
+ "/sell?productRegion=DE&locale=de_DE");
|
||||
URL createdUrl1 = demoSeller.createApiUrl(productId1);
|
||||
Assertions.assertEquals(expectedUrl1, createdUrl1);
|
||||
|
||||
// Test case 2
|
||||
String productId2 = "67890";
|
||||
URL expectedUrl2 = new URL(
|
||||
"https://www.example.com/api/products/2020-08-26/"
|
||||
+ "products/"
|
||||
+ productId2
|
||||
+ "/sell?productRegion=DE&locale=de_DE");
|
||||
URL createdUrl2 = demoSeller.createApiUrl(productId2);
|
||||
Assertions.assertEquals(expectedUrl2, createdUrl2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDataTarget_ReturnsExpectedDataOrigin() {
|
||||
String dataTarget = demoSeller.getDataTarget();
|
||||
assertEquals(demoDataTarget, dataTarget);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getApiKey_ReturnsExpectedApiKey() {
|
||||
String apiKey = demoSeller.getApiKey();
|
||||
assertEquals(demoApiKey, apiKey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user