Skip to content

Commit 353e02d

Browse files
committed
test: replace calls to API with Wiremock
1 parent 16085a9 commit 353e02d

File tree

13 files changed

+186
-16
lines changed

13 files changed

+186
-16
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@
144144
<scope>test</scope>
145145
</dependency>
146146

147+
<dependency>
148+
<groupId>com.github.tomakehurst</groupId>
149+
<artifactId>wiremock-jre8-standalone</artifactId>
150+
<version>2.35.0</version>
151+
<scope>test</scope>
152+
</dependency>
153+
147154
</dependencies>
148155
<build>
149156
<pluginManagement>

src/test/java/com/mytaxi/apis/phrase/api/locale/PhraseLocaleAPITest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mytaxi.apis.phrase.api.locale;
22

3+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
34
import com.mytaxi.apis.phrase.api.locale.dto.PhraseLocaleDTO;
45
import com.mytaxi.apis.phrase.config.TestConfig;
56
import com.mytaxi.apis.phrase.domainobject.locale.PhraseBranch;
@@ -10,6 +11,7 @@
1011
import org.aeonbits.owner.ConfigFactory;
1112
import org.junit.Before;
1213
import org.junit.Ignore;
14+
import org.junit.Rule;
1315
import org.junit.Test;
1416
import org.junit.runner.RunWith;
1517
import org.mockito.ArgumentCaptor;
@@ -20,6 +22,7 @@
2022
import org.springframework.http.ResponseEntity;
2123
import org.springframework.web.client.RestTemplate;
2224

25+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
2326
import static org.junit.Assert.assertEquals;
2427
import static org.junit.Assert.assertNotNull;
2528
import static org.junit.Assert.assertTrue;
@@ -32,6 +35,8 @@
3235
@RunWith(MockitoJUnitRunner.class)
3336
public class PhraseLocaleAPITest
3437
{
38+
@Rule
39+
public WireMockRule wireMockRule = new WireMockRule(options().port(9999));
3540

3641
private RestTemplate restTemplate;
3742

@@ -58,7 +63,10 @@ public void testListLocales_integration() throws Exception
5863
{
5964
// GIVEN
6065
String authToken = cfg.authToken();
61-
PhraseLocaleAPI phraseAppApiV2 = new PhraseLocaleAPI(authToken);
66+
String host = cfg.host();
67+
String scheme = cfg.scheme();
68+
69+
PhraseLocaleAPI phraseAppApiV2 = new PhraseLocaleAPI(authToken, scheme, host);
6270

6371
String projectId = cfg.projectId();
6472
List<String> branches = cfg.branches();
@@ -101,8 +109,10 @@ public void listLocales_getTwoTimes_statusCode200and304_XRateLimitRemainingNotCh
101109
String authToken = cfg.authToken();
102110
String projectId = cfg.projectId();
103111
List<String> branches = cfg.branches();
112+
String host = cfg.host();
113+
String scheme = cfg.scheme();
104114

105-
PhraseLocaleAPI phraseLocaleAPI = Mockito.spy(new PhraseLocaleAPI(authToken));
115+
PhraseLocaleAPI phraseLocaleAPI = Mockito.spy(new PhraseLocaleAPI(authToken, scheme, host));
106116

107117
// WHEN doing two request
108118
List<PhraseProject> phraseProject1 = phraseLocaleAPI.listLocales(Collections.singletonList(projectId), branches);

src/test/java/com/mytaxi/apis/phrase/api/locale/PhraseLocaleAPITestNew.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mytaxi.apis.phrase.api.locale;
22

3+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
34
import com.mytaxi.apis.phrase.api.locale.dto.PhraseLocaleDTO;
45
import com.mytaxi.apis.phrase.config.TestConfig;
56
import com.mytaxi.apis.phrase.domainobject.locale.PhraseBranch;
@@ -10,6 +11,7 @@
1011
import org.aeonbits.owner.ConfigFactory;
1112
import org.junit.Before;
1213
import org.junit.Ignore;
14+
import org.junit.Rule;
1315
import org.junit.Test;
1416
import org.junit.runner.RunWith;
1517
import org.mockito.ArgumentCaptor;
@@ -20,6 +22,7 @@
2022
import org.springframework.http.ResponseEntity;
2123
import org.springframework.web.client.RestTemplate;
2224

25+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
2326
import static org.junit.Assert.assertEquals;
2427
import static org.junit.Assert.assertNotNull;
2528
import static org.junit.Assert.assertTrue;
@@ -35,6 +38,8 @@
3538
@RunWith(MockitoJUnitRunner.class)
3639
public class PhraseLocaleAPITestNew
3740
{
41+
@Rule
42+
public WireMockRule wireMockRule = new WireMockRule(options().port(9999));
3843

3944
private RestTemplate restTemplate;
4045

src/test/java/com/mytaxi/apis/phrase/api/localedownload/PhraseLocaleDownloadAPITest.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.mytaxi.apis.phrase.api.localedownload;
22

3+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
34
import com.mytaxi.apis.phrase.api.format.Format;
45
import com.mytaxi.apis.phrase.api.format.JavaPropertiesFormat;
56
import com.mytaxi.apis.phrase.config.TestConfig;
67
import java.util.List;
78
import org.aeonbits.owner.ConfigFactory;
89
import org.junit.Before;
10+
import org.junit.Rule;
911
import org.junit.Test;
1012
import org.junit.runner.RunWith;
1113
import org.mockito.ArgumentCaptor;
@@ -15,9 +17,9 @@
1517
import org.springframework.http.HttpStatus;
1618
import org.springframework.http.ResponseEntity;
1719

20+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
1821
import static org.assertj.core.api.Assertions.assertThat;
19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.*;
2123
import static org.mockito.Matchers.anyString;
2224
import static org.mockito.Matchers.eq;
2325
import static org.mockito.Mockito.times;
@@ -26,6 +28,8 @@
2628
@RunWith(MockitoJUnitRunner.class)
2729
public class PhraseLocaleDownloadAPITest
2830
{
31+
@Rule
32+
public WireMockRule wireMockRule = new WireMockRule(options().port(9999));
2933

3034
@Captor
3135
ArgumentCaptor<ResponseEntity<byte[]>> responseEntityCaptor;
@@ -47,8 +51,10 @@ public void tesDownloadLocales_integration() throws Exception
4751
String authToken = cfg.authToken();
4852
String projectId = cfg.projectId();
4953
String localeIdDe = cfg.localeIdDe();
54+
String host = cfg.host();
55+
String scheme = cfg.scheme();
5056

51-
PhraseLocaleDownloadAPI localeDownloadAPI = new PhraseLocaleDownloadAPI(authToken);
57+
PhraseLocaleDownloadAPI localeDownloadAPI = new PhraseLocaleDownloadAPI(authToken, scheme, host);
5258

5359
// WHEN
5460
byte[] fileBytes = localeDownloadAPI.downloadLocale(projectId, localeIdDe);
@@ -64,8 +70,10 @@ public void tesDownloadLocales_etag()
6470
String authToken = cfg.authToken();
6571
String projectId = cfg.projectId();
6672
String localeIdDe = cfg.localeIdDe();
73+
String host = cfg.host();
74+
String scheme = cfg.scheme();
6775

68-
PhraseLocaleDownloadAPI localeDownloadAPI = Mockito.spy(new PhraseLocaleDownloadAPI(authToken));
76+
PhraseLocaleDownloadAPI localeDownloadAPI = Mockito.spy(new PhraseLocaleDownloadAPI(authToken, scheme, host));
6977

7078
// WHEN doing two request
7179
byte[] fileBytes1 = localeDownloadAPI.downloadLocale(projectId, localeIdDe);
@@ -74,7 +82,7 @@ public void tesDownloadLocales_etag()
7482
// THEN assert same result
7583
assertNotNull(fileBytes1);
7684
assertNotNull(fileBytes2);
77-
assertEquals(fileBytes1, fileBytes2);
85+
assertArrayEquals(fileBytes1, fileBytes2);
7886

7987
// AND assert status codes 200 and 304 to verify E-Tag handling
8088
verify(localeDownloadAPI, times(2)).handleResponse(eq(projectId), anyString(), responseEntityCaptor.capture());
@@ -94,8 +102,10 @@ public void tesDownloadLocales_withFormatOptions() throws Exception
94102
String projectId = cfg.projectId();
95103
String localeIdDe = cfg.localeIdDe();
96104
List<String> branches = cfg.branches();
105+
String host = cfg.host();
106+
String scheme = cfg.scheme();
97107

98-
PhraseLocaleDownloadAPI localeDownloadAPI = new PhraseLocaleDownloadAPI(authToken);
108+
PhraseLocaleDownloadAPI localeDownloadAPI = new PhraseLocaleDownloadAPI(authToken, scheme, host);
99109

100110
Format format = JavaPropertiesFormat.newBuilder()
101111
.setEscapeSingleQuotes(false)

src/test/java/com/mytaxi/apis/phrase/api/localedownload/PhraseLocaleDownloadAPITestNew.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
package com.mytaxi.apis.phrase.api.localedownload;
22

3+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
34
import com.mytaxi.apis.phrase.api.format.Format;
45
import com.mytaxi.apis.phrase.api.format.JavaPropertiesFormat;
56
import com.mytaxi.apis.phrase.config.TestConfig;
67
import java.util.List;
78
import org.aeonbits.owner.ConfigFactory;
89
import org.junit.Before;
10+
import org.junit.Rule;
911
import org.junit.Test;
1012

13+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
1114
import static org.junit.Assert.assertNotNull;
1215

1316
/**
1417
* Created by m.winkelmann on 24.11.15.
1518
*/
1619
public class PhraseLocaleDownloadAPITestNew
1720
{
21+
@Rule
22+
public WireMockRule wireMockRule = new WireMockRule(options().port(9999));
1823

1924
private TestConfig cfg;
2025

src/test/java/com/mytaxi/apis/phrase/api/translation/PhraseTranslationAPITest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mytaxi.apis.phrase.api.translation;
22

3+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
34
import com.mytaxi.apis.phrase.api.locale.dto.PhraseLocaleDTO;
45
import com.mytaxi.apis.phrase.api.translation.dto.PhraseKeyDTO;
56
import com.mytaxi.apis.phrase.api.translation.dto.PhraseTranslationDTO;
@@ -12,6 +13,7 @@
1213
import org.aeonbits.owner.ConfigFactory;
1314
import org.junit.Assert;
1415
import org.junit.Before;
16+
import org.junit.Rule;
1517
import org.junit.Test;
1618
import org.mockito.Matchers;
1719
import org.mockito.Mockito;
@@ -22,11 +24,16 @@
2224
import org.springframework.http.ResponseEntity;
2325
import org.springframework.web.client.RestTemplate;
2426

27+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
28+
2529
/**
2630
* Created by m.winkelmann on 05.11.15.
2731
*/
2832
public class PhraseTranslationAPITest
2933
{
34+
@Rule
35+
public WireMockRule wireMockRule = new WireMockRule(options().port(9999));
36+
3037
private RestTemplate restTemplate;
3138

3239
private PhraseTranslationAPI translationAPI;
@@ -118,7 +125,10 @@ public void testListTranslations() throws Exception
118125
{
119126
// GIVEN
120127
String authToken = cfg.authToken();
121-
PhraseTranslationAPI translationAPI = new PhraseTranslationAPI(authToken);
128+
String host = cfg.host();
129+
String scheme = cfg.scheme();
130+
131+
PhraseTranslationAPI translationAPI = new PhraseTranslationAPI(authToken, scheme, host);
122132

123133
String projectId = cfg.projectId();
124134

src/test/java/com/mytaxi/apis/phrase/api/translation/PhraseTranslationAPITestNew.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mytaxi.apis.phrase.api.translation;
22

3+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
34
import com.mytaxi.apis.phrase.api.locale.dto.PhraseLocaleDTO;
45
import com.mytaxi.apis.phrase.api.translation.dto.PhraseKeyDTO;
56
import com.mytaxi.apis.phrase.api.translation.dto.PhraseTranslationDTO;
@@ -12,6 +13,7 @@
1213
import org.aeonbits.owner.ConfigFactory;
1314
import org.junit.Assert;
1415
import org.junit.Before;
16+
import org.junit.Rule;
1517
import org.junit.Test;
1618
import org.mockito.Matchers;
1719
import org.mockito.Mockito;
@@ -22,11 +24,15 @@
2224
import org.springframework.http.ResponseEntity;
2325
import org.springframework.web.client.RestTemplate;
2426

27+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
28+
2529
/**
2630
* Created by m.winkelmann on 05.11.15.
2731
*/
2832
public class PhraseTranslationAPITestNew
2933
{
34+
@Rule
35+
public WireMockRule wireMockRule = new WireMockRule(options().port(9999));
3036
private RestTemplate restTemplate;
3137

3238
private PhraseTranslationAPI translationAPI;

src/test/java/com/mytaxi/apis/phrase/config/TestConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
*/
99
public interface TestConfig extends Config
1010
{
11-
@DefaultValue("${ENV_PHRASE_AUTHTOKEN}")
11+
@DefaultValue("token-1234")
1212
String authToken();
1313

14-
@DefaultValue("${ENV_PHRASE_PROJECTID}")
14+
@DefaultValue("proj-1234")
1515
String projectId();
1616

17-
@DefaultValue("${ENV_PHRASE_BRANCHES}")
17+
@DefaultValue("master")
1818
List<String> branches();
1919

20-
@DefaultValue("${ENV_PHRASE_LOCALEID_DE}")
20+
@DefaultValue("loc-1234")
2121
String localeIdDe();
2222

23-
@DefaultValue("${ENV_PHRASE_HOST}")
23+
@DefaultValue("localhost:9999")
2424
String host();
2525

26-
@DefaultValue("${ENV_PHRASE_SCHEME}")
26+
@DefaultValue("http")
2727
String scheme();
2828
}

src/test/java/com/mytaxi/apis/phrase/tasks/PhraseAppSyncTaskTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mytaxi.apis.phrase.tasks;
22

3+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
34
import com.google.common.collect.ImmutableList;
45
import com.mytaxi.apis.phrase.api.format.Format;
56
import com.mytaxi.apis.phrase.api.format.JavaPropertiesFormat;
@@ -16,14 +17,18 @@
1617
import org.aeonbits.owner.ConfigFactory;
1718
import org.junit.Before;
1819
import org.junit.Ignore;
20+
import org.junit.Rule;
1921
import org.junit.Test;
2022

23+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
2124
import static org.junit.Assert.assertEquals;
2225
import static org.junit.Assert.assertFalse;
2326
import static org.junit.Assert.assertTrue;
2427

2528
public class PhraseAppSyncTaskTest
2629
{
30+
@Rule
31+
public WireMockRule wireMockRule = new WireMockRule(options().port(9999));
2732
private TestConfig cfg;
2833

2934

@@ -75,7 +80,7 @@ private void testRun(Format format, List<ExpectedEntry> expectedEntries) throws
7580
String uuid = UUID.randomUUID().toString();
7681

7782
//
78-
PhraseAppSyncTask phraseAppSyncTask = new PhraseAppSyncTask(cfg.authToken(), cfg.projectId());
83+
PhraseAppSyncTask phraseAppSyncTask = new PhraseAppSyncTask(cfg.authToken(), cfg.projectId(), cfg.scheme(), cfg.host());
7984
phraseAppSyncTask.setMessagesFoldername(uuid);
8085
phraseAppSyncTask.setFormat(format);
8186
phraseAppSyncTask.run();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
key=value

0 commit comments

Comments
 (0)