Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test poijson interface #5

Merged
merged 5 commits into from
Feb 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'org.json:json:20140107'
compile project(path: ':android-core')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
Expand All @@ -36,4 +37,5 @@ dependencies {
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2'
androidTestCompile 'com.android.support:support-annotations:23.1.1'
compile 'com.github.satyan:sugar:1.4'
compile files('src/main/assets/libs/jsonassert-1.2.3.jar')
}
Binary file added app/src/main/assets/libs/jsonassert-1.2.3.jar
Binary file not shown.
7 changes: 4 additions & 3 deletions app/src/main/java/soen390/mapx/model/POI.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public class POI extends SugarRecord {

/**
* Discriminant for type of the POI between Transition point, Service point or Exhibition
* Is a String instead of char because JSONObject encodes char to ascii
*/
private char type;
private String type;

/**
* Subtype relevant to transition (i (intersection), s (stairs), e (elevator))
Expand Down Expand Up @@ -60,11 +61,11 @@ public void setyCoord(int yCoord) {
this.yCoord = yCoord;
}

public char getType() {
public String getType() {
return type;
}

public void setType(char type) {
public void setType(String type) {
this.type = type;
}

Expand Down
38 changes: 28 additions & 10 deletions app/src/main/java/soen390/mapx/webapp/POIJSInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class POIJSInterface {

private Context context;

public POIJSInterface() {}

public POIJSInterface(Context context) {
this.context = context;
Expand All @@ -28,20 +29,37 @@ public POIJSInterface(Context context) {
* @return JSON with POIs information
*/
public String getPOIsJSON() {
List<POI> pois = POI.listAll(POI.class);
return buildPOIJSON(pois).toString();
}

/**
* Return JSON that contains information of the museum floors
* @return JSON string of the floor information
*/
public String getFloorJSON(){
List<Floor> floors = Floor.listAll(Floor.class);
return buildFloorJSON(floors).toString();
}

/**
* Given a list of POIs build a JSON corresponding to it
* @param pois List of POIs
* @return JSON corresponding to the lsit of POIs
*/
public JSONObject buildPOIJSON(List<POI> pois){
JSONObject jsonObj = new JSONObject();

JSONArray poiArr = new JSONArray();
JSONObject poisObj;

List<POI> pois = POI.listAll(POI.class);

try{
for(POI poi: pois) {
poisObj = new JSONObject();
poisObj.put("_id", poi.getId());
poisObj.put("title", poi.getTitle());
poisObj.put("type", poi.getType());
poisObj.put("floor", poi);
poisObj.put("floor", poi.getFloorId());
poisObj.put("x_coord", poi.getxCoord());
poisObj.put("y_coord", poi.getyCoord());
poiArr.put(poisObj);
Expand All @@ -53,20 +71,19 @@ public String getPOIsJSON() {
e.printStackTrace();
}

return jsonObj.toString();
return jsonObj;
}
/**
* Return JSON that contains information of the museum floors
* @return JSON string of the floor information
* Given a list of floors build a JSON corresponding to it
* @param floors List of floors
* @return JSON corresponding to the list of floors
*/
public String getFloorJSON(){
public JSONObject buildFloorJSON(List<Floor> floors){
JSONObject jsonObj = new JSONObject();

JSONArray floorArr = new JSONArray();
JSONObject floorObj;

List<Floor> floors = Floor.listAll(Floor.class);

try{
for(Floor floor: floors) {
floorObj = new JSONObject();
Expand All @@ -83,7 +100,8 @@ public String getFloorJSON(){
e.printStackTrace();
}

return jsonObj.toString();
return jsonObj;

}

}
57 changes: 55 additions & 2 deletions app/src/test/java/soen390/mapx/webapp/POIJSInterfaceTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,66 @@
package soen390.mapx.webapp;

import android.content.Context;
import android.test.mock.MockContext;

import org.json.JSONException;
import org.junit.Before;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;

import java.util.ArrayList;
import java.util.List;

import soen390.mapx.model.Floor;
import soen390.mapx.model.POI;

import static org.junit.Assert.*;

public class POIJSInterfaceTest {

private POIJSInterface poi_int;
Context context = new MockContext();
List<POI> list_poi;
List<Floor> list_floor;

@Before
public void initialize() {
list_poi = new ArrayList<POI>();
poi_int = new POIJSInterface(context);
POI poi = new POI();
poi.setId((long) 1);
poi.setTitle("POI_1");
poi.setType("e");
poi.setFloorId((long) 1);
poi.setxCoord(75);
poi.setyCoord(100);
list_poi.add(poi);

list_floor = new ArrayList<Floor>();
Floor floor = new Floor();
floor.setId((long) 1);
floor.setFloorNum(1);
floor.setImageFilePath("tiles/floor_1.jpg");
floor.setImageHeight(700);
floor.setImageWidth(1800);
list_floor.add(floor);
}

@Test
public void testgetPOIsJSON() {
try {
JSONAssert.assertEquals("{\"poi\":[{\"x_coord\":75,\"y_coord\":100,\"_id\":1,\"title\":\"POI_1\",\"type\":\"e\",\"floor\":1}]}", poi_int.buildPOIJSON(list_poi), true);
}catch(JSONException e){
e.printStackTrace();
}
}

@Test
public void testgetPOIsJSON(){
assertEquals(true, true);
public void testgetFloorJSON(){
try{
JSONAssert.assertEquals("{\"floor\":[{\"floor_num\":1,\"floor_path\":\"tiles/floor_1.jpg\",\"floor_width\":1800,\"floor_height\":700}]}", poi_int.buildFloorJSON(list_floor), true);
} catch (JSONException e) {
e.printStackTrace();
}
}
}