forked from Archives/Athou_commafeed
Merge pull request #942 from pklink/tests
Add tests for PubSubService and FeedUtils.removeTrailingSlash()
This commit is contained in:
8
pom.xml
8
pom.xml
@@ -255,7 +255,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.12</version>
|
<version>1.7.30</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -483,5 +483,11 @@
|
|||||||
<version>2.0.11-beta</version>
|
<version>2.0.11-beta</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mock-server</groupId>
|
||||||
|
<artifactId>mockserver-junit-rule</artifactId>
|
||||||
|
<version>5.11.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -78,4 +78,19 @@ public class FeedUtilsTest {
|
|||||||
String source = "<source>T´l´phone ′</source>";
|
String source = "<source>T´l´phone ′</source>";
|
||||||
Assert.assertEquals("<source>T´l´phone ′</source>", FeedUtils.replaceHtmlEntitiesWithNumericEntities(source));
|
Assert.assertEquals("<source>T´l´phone ′</source>", FeedUtils.replaceHtmlEntitiesWithNumericEntities(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveTrailingSlash() {
|
||||||
|
final String url = "http://localhost/";
|
||||||
|
final String result = FeedUtils.removeTrailingSlash(url);
|
||||||
|
Assert.assertEquals("http://localhost", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveTrailingSlash_lastSlashOnly() {
|
||||||
|
final String url = "http://localhost//";
|
||||||
|
final String result = FeedUtils.removeTrailingSlash(url);
|
||||||
|
Assert.assertEquals("http://localhost/", result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package com.commafeed.backend.service;
|
||||||
|
|
||||||
|
import com.commafeed.CommaFeedConfiguration;
|
||||||
|
import com.commafeed.backend.feed.FeedQueues;
|
||||||
|
import com.commafeed.backend.model.Feed;
|
||||||
|
import org.apache.http.HttpHeaders;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Answers;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
import org.mockserver.client.MockServerClient;
|
||||||
|
import org.mockserver.junit.MockServerRule;
|
||||||
|
import org.mockserver.model.MediaType;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
import static org.mockserver.model.HttpRequest.request;
|
||||||
|
import static org.mockserver.model.HttpResponse.response;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class PubSubServiceTest {
|
||||||
|
|
||||||
|
PubSubService underTest;
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public MockServerRule mockServerRule = new MockServerRule(this, 22441);
|
||||||
|
public MockServerClient mockServerClient;
|
||||||
|
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
CommaFeedConfiguration config;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
FeedQueues queues;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
Feed feed;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
|
underTest = new PubSubService(config, queues);
|
||||||
|
|
||||||
|
// setup feed
|
||||||
|
feed = mock(Feed.class);
|
||||||
|
when(feed.getPushHub()).thenReturn("http://localhost:22441/hub");
|
||||||
|
when(feed.getPushTopic()).thenReturn("foo");
|
||||||
|
|
||||||
|
// setup config
|
||||||
|
when(config.getApplicationSettings().getPublicUrl()).thenReturn("http://localhost:22441/hub");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void subscribe_200() {
|
||||||
|
// Arrange
|
||||||
|
mockServerClient
|
||||||
|
.when(request().withMethod("POST"))
|
||||||
|
.respond(response().withStatusCode(200));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
underTest.subscribe(feed);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
mockServerClient.verify(request()
|
||||||
|
.withContentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
|
.withHeader(HttpHeaders.USER_AGENT, "CommaFeed")
|
||||||
|
.withMethod("POST")
|
||||||
|
.withPath("/hub"));
|
||||||
|
verify(feed, never()).setPushTopic(anyString());
|
||||||
|
verifyZeroInteractions(queues);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void subscribe_400_withPushpressError() {
|
||||||
|
// Arrange
|
||||||
|
mockServerClient
|
||||||
|
.when(request().withMethod("POST"))
|
||||||
|
.respond(response().withStatusCode(400).withBody(" is value is not allowed. You may only subscribe to"));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
underTest.subscribe(feed);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
verify(feed).setPushTopic(anyString());
|
||||||
|
verify(queues).giveBack(feed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void subscribe_400_withoutPushpressError() {
|
||||||
|
// Arrange
|
||||||
|
mockServerClient
|
||||||
|
.when(request().withMethod("POST"))
|
||||||
|
.respond(response().withStatusCode(400));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
underTest.subscribe(feed);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
verify(feed, never()).setPushTopic(anyString());
|
||||||
|
verifyZeroInteractions(queues);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user