This repository has been archived by the owner on Dec 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ApplETS/dev
Update : Fix Cooptel
- Loading branch information
Showing
14 changed files
with
539 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
tmp/** | ||
tmp/**/* | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
docker build -t applets_api_db docker-dir/db | ||
docker run --name applets_api_db -p 5432:5432 -e POSTGRES_PASSWORD=postgres -d applets_api_db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/test/java/applets/etsmtl/ca/news/EventsResourcesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package news; | ||
|
||
import applets.etsmtl.ca.news.EventsResources; | ||
import applets.etsmtl.ca.news.db.EventDAO; | ||
import applets.etsmtl.ca.news.db.SourceDAO; | ||
import applets.etsmtl.ca.news.model.Event; | ||
import applets.etsmtl.ca.news.model.Source; | ||
import org.glassfish.jersey.server.ResourceConfig; | ||
import org.glassfish.jersey.test.JerseyTest; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import javax.ws.rs.core.Application; | ||
import javax.ws.rs.core.GenericType; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Created by gnut3ll4 on 8/21/16. | ||
*/ | ||
public class EventsResourcesTest extends JerseyTest { | ||
|
||
@Mock | ||
private EventDAO eventDAO; | ||
|
||
@Mock | ||
private SourceDAO sourceDAO; | ||
|
||
@Override | ||
protected Application configure() { | ||
MockitoAnnotations.initMocks(this); | ||
EventsResources resource = new EventsResources(eventDAO, sourceDAO); | ||
ResourceConfig config = new ResourceConfig(); | ||
config.register(resource); | ||
return config; | ||
} | ||
|
||
@Test | ||
public void testGetEvents() { | ||
String sourceKey = "aeets", message = "Ceci est un test"; | ||
|
||
Event event = new Event(); | ||
event.setId_source(sourceKey); | ||
event.setNom(message); | ||
|
||
ArrayList<Event> list = new ArrayList<>(); | ||
list.add(event); | ||
list.add(event); | ||
when(eventDAO.findFollowingEvents(sourceKey)).thenReturn(list); | ||
|
||
Source source = new Source(); | ||
source.setKey(sourceKey); | ||
when(sourceDAO.find(sourceKey)).thenReturn(source); | ||
|
||
List<Event> response = target("/events/list/" + sourceKey).request().get(new GenericType<List<Event>>() { | ||
}); | ||
|
||
Assert.assertTrue(message.equals(response.get(0).getNom())); | ||
Assert.assertTrue(response.size() == list.size()); | ||
} | ||
|
||
@Test | ||
public void testGetSources() { | ||
ArrayList<Source> sources = new ArrayList<>(); | ||
|
||
Source source1 = new Source(); | ||
source1.setName("source1"); | ||
source1.setType("facebook"); | ||
|
||
sources.add(source1); | ||
sources.add(source1); | ||
|
||
when(sourceDAO.findByType("facebook")).thenReturn(sources); | ||
|
||
List<Source> response = target("/events/sources").request().get(new GenericType<List<Source>>() { | ||
}); | ||
|
||
Assert.assertTrue("source1".equals(response.get(0).getName())); | ||
Assert.assertTrue(response.size() == sources.size()); | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/test/java/applets/etsmtl/ca/partners/PartnersResourcesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package partners; | ||
|
||
import applets.etsmtl.ca.news.model.Event; | ||
import applets.etsmtl.ca.partners.Partner; | ||
import applets.etsmtl.ca.partners.PartnersResource; | ||
import okhttp3.mockwebserver.MockResponse; | ||
import okhttp3.mockwebserver.MockWebServer; | ||
import org.glassfish.jersey.server.ResourceConfig; | ||
import org.glassfish.jersey.test.JerseyTest; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import javax.ws.rs.core.Application; | ||
import javax.ws.rs.core.GenericType; | ||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by gnut3ll4 on 8/21/16. | ||
*/ | ||
public class PartnersResourcesTest extends JerseyTest { | ||
|
||
@Override | ||
protected Application configure() { | ||
return new ResourceConfig(PartnersResource.class); | ||
} | ||
|
||
@Test | ||
public void testGetPartners() { | ||
MockWebServer server = new MockWebServer(); | ||
|
||
try { | ||
final String filePath = getClass().getResource("/clubapplets_partners_body.html").getPath(); | ||
String partnersHtml = readFile(filePath, StandardCharsets.UTF_8); | ||
|
||
server.enqueue(new MockResponse().setBody(partnersHtml)); | ||
server.start(); | ||
String url = server.url("/partners").toString(); | ||
PartnersResource.PARTNERS_URL = url; | ||
|
||
List<Partner> response = target("/partners").request().get(new GenericType<List<Partner>>() { | ||
}); | ||
|
||
Assert.assertTrue(response.size() > 0); | ||
|
||
PartnersResource.PARTNERS_URL = ""; | ||
|
||
//Test caching | ||
response = target("/partners").request().get(new GenericType<List<Partner>>() { | ||
}); | ||
Assert.assertTrue(response.size() > 0); | ||
|
||
server.shutdown(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
String readFile(String path, Charset encoding) throws IOException { | ||
byte[] encoded = Files.readAllBytes(Paths.get(path)); | ||
return new String(encoded, encoding); | ||
} | ||
|
||
|
||
} | ||
|
||
|
Oops, something went wrong.