83 lines
2.6 KiB
Java
83 lines
2.6 KiB
Java
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;
|
|
|
|
import de.rwu.easydrop.model.Webshop;
|
|
|
|
class AmazonSellerTest {
|
|
private AmazonSeller demoSeller;
|
|
|
|
private static String demoApiKey = "my-api-key";
|
|
private static String demoApiUrl = "https://www.example.com/api";
|
|
private static Webshop demoDataTarget = Webshop.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() {
|
|
Webshop dataTarget = demoSeller.getDataTarget();
|
|
assertEquals(demoDataTarget, dataTarget);
|
|
}
|
|
|
|
@Test
|
|
void getApiKey_ReturnsExpectedApiKey() {
|
|
String apiKey = demoSeller.getApiKey();
|
|
assertEquals(demoApiKey, apiKey);
|
|
}
|
|
}
|