aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src/test/java/com/juick/service
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-10-15 05:37:18 +0300
committerGravatar Vitaly Takmazov2017-10-15 19:50:15 +0300
commit9a4add44ecbd32dea6ac3d30fd81ae1ac82e3dbc (patch)
tree38b7a4ba01d1fc47841d3ba2787209b2b2a2de9e /juick-server-jdbc/src/test/java/com/juick/service
parentaeda9e3733e685f5069b5cfbb16272cd32073fa0 (diff)
api: ImagesService
Diffstat (limited to 'juick-server-jdbc/src/test/java/com/juick/service')
-rw-r--r--juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java15
-rw-r--r--juick-server-jdbc/src/test/java/com/juick/service/MockImagesService.java62
2 files changed, 73 insertions, 4 deletions
diff --git a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java
index 47699dbc..f5701b0c 100644
--- a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java
+++ b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java
@@ -22,11 +22,12 @@ import com.juick.Tag;
import com.juick.User;
import com.juick.configuration.RepositoryConfiguration;
import com.juick.server.helpers.AnonymousUser;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.*;
+import org.junit.runner.RunWith;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.inject.Inject;
import java.util.Collections;
@@ -38,6 +39,7 @@ import static org.hamcrest.Matchers.equalTo;
/**
* Created by aalexeev on 11/25/16.
*/
+@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = RepositoryConfiguration.class)
public class MessageServiceTest extends AbstractJUnit4SpringContextTests {
@Inject
@@ -59,10 +61,15 @@ public class MessageServiceTest extends AbstractJUnit4SpringContextTests {
int ugnichId, freefdId, mid;
+ private static boolean setUpIsDone = false;
+
@Before
public void createUgniches() {
- ugnichId = userService.createUser("ugnich", "secret");
- freefdId = userService.createUser("freefd", "secret");
+ if (!setUpIsDone) {
+ ugnichId = userService.createUser("ugnich", "secret");
+ freefdId = userService.createUser("freefd", "secret");
+ setUpIsDone = true;
+ }
}
@Test
diff --git a/juick-server-jdbc/src/test/java/com/juick/service/MockImagesService.java b/juick-server-jdbc/src/test/java/com/juick/service/MockImagesService.java
new file mode 100644
index 00000000..6f47de91
--- /dev/null
+++ b/juick-server-jdbc/src/test/java/com/juick/service/MockImagesService.java
@@ -0,0 +1,62 @@
+package com.juick.service;
+
+import com.juick.Attachment;
+import com.juick.Message;
+import com.juick.Photo;
+import org.springframework.util.StringUtils;
+
+import java.io.File;
+import java.nio.file.Paths;
+
+public class MockImagesService implements ImagesService {
+ @Override
+ public void setAttachmentMetadata(String imgDir, String baseUrl, Message msg) throws Exception {
+ if (!StringUtils.isEmpty(msg.getAttachmentType())) {
+ Photo photo = new Photo();
+ if (msg.getRid()> 0) {
+ photo.setSmall(String.format("%sphotos-512/%d-%d.%s", baseUrl, msg.getMid(), msg.getRid(), msg.getAttachmentType()));
+ photo.setMedium(String.format("%sphotos-1024/%d-%d.%s", baseUrl, msg.getMid(), msg.getRid(), msg.getAttachmentType()));
+ photo.setThumbnail(String.format("%sps/%d-%d.%s", baseUrl, msg.getMid(), msg.getRid(), msg.getAttachmentType()));
+ } else {
+ photo.setSmall(String.format("%sphotos-512/%d.%s", baseUrl, msg.getMid(), msg.getAttachmentType()));
+ photo.setMedium(String.format("%sphotos-1024/%d.%s", baseUrl, msg.getMid(), msg.getAttachmentType()));
+ photo.setThumbnail(String.format("%sps/%d.%s", baseUrl, msg.getMid(), msg.getAttachmentType()));
+ }
+ msg.setPhoto(photo);
+ StringBuilder builder = new StringBuilder();
+ builder.append(baseUrl);
+ builder.append(msg.getAttachmentType().equals("mp4") ? "video" : "p");
+ builder.append("/").append(msg.getMid());
+ if (msg.getRid() > 0) {
+ builder.append("-").append(msg.getRid());
+ }
+ builder.append(".").append(msg.getAttachmentType());
+ String originalUrl = builder.toString();
+
+ Attachment original = new Attachment();
+ original.setUrl(originalUrl);
+ original.setHeight(2048);
+ original.setWidth(2048);
+
+ Attachment medium = new Attachment();
+ medium.setUrl(photo.getMedium());
+ medium.setWidth(1024);
+ medium.setHeight(1024);
+ original.setMedium(medium);
+
+ Attachment small = new Attachment();
+ small.setUrl(photo.getSmall());
+ small.setWidth(1024);
+ small.setHeight(1024);
+ original.setSmall(small);
+
+ Attachment thumb = new Attachment();
+ thumb.setUrl(photo.getMedium());
+ thumb.setWidth(1024);
+ thumb.setHeight(1024);
+ original.setThumbnail(thumb);
+
+ msg.setAttachment(original);
+ }
+ }
+}