Skip to content

Commit

Permalink
Merge pull request #39 from UMM-CSci-3601-S17/photoTestswithTony!
Browse files Browse the repository at this point in the history
Photo tests exist
  • Loading branch information
real-mj-song authored Apr 28, 2017
2 parents 153941e + 546c947 commit ee165b2
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions server/src/test/java/umm3601/digitalDisplayGarden/TestPhotos.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,93 @@
package umm3601.digitalDisplayGarden;


import com.mongodb.MongoClient;
import com.mongodb.client.MongoDatabase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertTrue;

public class TestPhotos {
Photos photos = new Photos("data-for-testing-only");
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase("data-for-testing-only");

boolean photosExist;

@Before
public void flagDeletePos() {
if (Files.notExists(Paths.get(".photos/"))) {
photosExist = false;
} else {
photosExist = true;
}
}

@After
public void delFolders() {
deleteDirectory(new File(".photos/"+"second uploadId"));
if (!photosExist) {
deleteDirectory(new File(".photos/"));
}
}

@Test
public void smallImageTest() throws IOException {

BufferedImage test1 = new BufferedImage(80,80,BufferedImage.TYPE_BYTE_BINARY);

photos.saveImage("one",test1,"second uploadId");

File foo = new File (".photos/second uploadId/one.jpeg");

assertTrue(foo.exists());
}

@Test(expected=IllegalArgumentException.class)
public void imageTooLargeTest() throws IOException {

BufferedImage test1 = new BufferedImage(50000,50000,BufferedImage.TYPE_BYTE_BINARY);

photos.saveImage("two",test1,"second uploadId");
}

@Test
public void giantLargeTest() throws IOException {

BufferedImage test1 = new BufferedImage(20000,15000,BufferedImage.TYPE_BYTE_BINARY);

photos.saveImage("three",test1,"second uploadId");

File foo = new File (".photos/second uploadId/three.jpeg");

assertTrue(foo.exists());
}


public static void deleteDirectory(File directory) {
if(directory.exists()){
File[] files = directory.listFiles();
if(null!=files){
for(int i=0; i<files.length; i++) {
if(files[i].isDirectory()) {
deleteDirectory(files[i]);
}
else {
files[i].delete();
}
}
}
}
directory.delete();
}
}

0 comments on commit ee165b2

Please sign in to comment.