public class CRUDPhotosTest extends BaseTest {
@Test
public void crudTest() throws Exception {
Response response = GET("/api/me/photos");
assertStatus(StatusCode.FOUND, response);
String location = response.getHeader("location");
assertNotNull(location);
Map<String, String> loginUserParams = new HashMap<String, String>();
loginUserParams.put("username", "eva.perez@B");
loginUserParams.put("password", "secret1");
// Login here so the following request will be authenticated:
response = POST(location, loginUserParams);
assertStatus(StatusCode.FOUND, response);
response = GET("/api/me/photos");
assertStatus(StatusCode.OK, response);
InputStream is = new ByteArrayInputStream(response.out.toByteArray());
Reader reader = new InputStreamReader(is);
Type dataType = new TypeToken<Data<Photo>>(){}.getType();
Data<Photo> data = new Gson().fromJson(reader, dataType);
assertTrue("La usuario eva perez no tiene ninguna foto", data.data.size()==0);
Map<String, String> parameters = new HashMap<String, String>();
Map<java.lang.String, java.io.File> files = new HashMap<java.lang.String, java.io.File>();
VirtualFile vfFile;
File image = null;
for (VirtualFile vf : Play.javaPath) {
vfFile = vf.child("atom-1.jpeg");
if(vfFile!=null && vfFile.exists()) {
image = vfFile.getRealFile();
break;
}
}
assertNotNull("El fichero atom-1.jpeg especificado no existe", image);
System.out.println("Exists: " + image.getAbsolutePath());
files.put("data", image);
response = POST("/api/me/photos", parameters, files);
location = response.getHeader("location");
response = GET(location);
assertStatus(StatusCode.OK, response);
dataType = new TypeToken<Photo>(){}.getType();
is = new ByteArrayInputStream(response.out.toByteArray());
reader = new InputStreamReader(is);