Skip to content

Commit

Permalink
Merge branch 'US07-AtribuirSegundaNotaAluno' into developer
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielsclimaco committed Jun 5, 2017
2 parents 6b86bd2 + 598caf6 commit 597048f
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 195 deletions.
6 changes: 6 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotations'
exclude module: 'recyclerview-v7'
}
compile project(':facebook-android-sdk-4.20.0')

compile 'com.android.support:appcompat-v7:25.3.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package fga.mds.gpp.trezentos.View;

import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.rule.ActivityTestRule;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.ListView;
import android.widget.TextView;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Rule;
Expand All @@ -17,8 +21,12 @@
import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static fga.mds.gpp.trezentos.R.id.frame;
import static fga.mds.gpp.trezentos.R.id.numberPicker1;
import static fga.mds.gpp.trezentos.R.id.recycler;
import static junit.framework.Assert.assertNotNull;
import static org.hamcrest.Matchers.anything;

Expand All @@ -45,11 +53,9 @@ public void setUp() {

@Test
public void shouldValidateStudentsFragmentInitialization(){
onView(withId(R.id.salas_item))
.perform(click());
onData(anything()).inAdapterView(withId(R.id.recycler))
.atPosition(0).perform(click());
onView(ViewMatchers.withText("STUDENTS"))
onView(withId(R.id.recycler)).perform(RecyclerViewActions
.actionOnItemAtPosition(5, click()));
onView(withText("STUDENTS"))
.perform(click());

assertNotNull(classRule);
Expand Down Expand Up @@ -87,16 +93,37 @@ public void shouldValidateStudentsFragmentInitialization(){

@Test
public void shouldClickOnButtonStudent(){
onView(withId(R.id.salas_item))
.perform(click());
onData(anything()).inAdapterView(withId(R.id.recycler))
.atPosition(0).perform(click());
onView(ViewMatchers.withText("STUDENTS"))
.perform(click());
onView(withId(R.id.recycler)).perform(RecyclerViewActions
.actionOnItemAtPosition(5, click()));
onView(withText("STUDENTS")).perform(click());

onView(withId(R.id.floating_btn)).perform(click());

assertNotNull(classRule);
}

@Test
public void shouldValidateFirstGrade(){
onView(withId(R.id.recycler)).perform(RecyclerViewActions.
actionOnItemAtPosition(5, click()));
onView(withId(R.id.recyclerExam)).perform(RecyclerViewActions.
actionOnItemAtPosition(0, click()));
onView(withText("Nota")).perform(click());
onView(withText("ok")).perform(click());
//onView(withId(R.id.action_update_grades)).perform(click());
assertTrue(true);
}

@Test
public void shouldValidateSecondGrade(){
onView(withId(R.id.recycler)).perform(RecyclerViewActions.
actionOnItemAtPosition(5, click()));
onView(withId(R.id.recyclerExam)).perform(RecyclerViewActions.
actionOnItemAtPosition(0, click()));
onView(withText("Nota 300")).perform(click());
onView(withText("ok")).perform(click());
//onView(withId(R.id.action_update_trezentos_grades)).perform(click());
assertTrue(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ExecutionException;

import fga.mds.gpp.trezentos.DAO.AddFirstGradesPost;
import fga.mds.gpp.trezentos.DAO.AddFirstGrades;
import fga.mds.gpp.trezentos.DAO.AddSecondGrades;
import fga.mds.gpp.trezentos.DAO.CreateExamPost;
import fga.mds.gpp.trezentos.DAO.getExamRequest;
import fga.mds.gpp.trezentos.Exception.UserClassException;
Expand Down Expand Up @@ -73,14 +73,21 @@ public String validateAddsFirstGrade(UserClass userClass, Exam exam)
Log.d("OBJETOS",exam.getClassOwnerEmail());
Log.d("OBJETOS",exam.getNameExam());

AddFirstGradesPost addFirstGradesPost = new AddFirstGradesPost(userClass, exam);

serverResponse = addFirstGradesPost.execute().get();
AddFirstGrades addFirstGrades = new AddFirstGrades(userClass, exam);
serverResponse = addFirstGrades.execute().get();

Log.d("JSON", serverResponse);
return serverResponse;
}

public String addSecondGrade(UserClass userClass, Exam exam) throws ExecutionException, InterruptedException {
String serverResponse;

AddSecondGrades addSecondGrades = new AddSecondGrades(userClass, exam);
serverResponse = addSecondGrades.execute().get();

return serverResponse;
}

//GET FROM API
public ArrayList<Exam> getExamsFromUser(String email, String userClassName) {
Expand Down Expand Up @@ -127,13 +134,12 @@ private Exam getUserExamFromJson(JSONObject jsonObject) {
exam.setNameExam(jsonObject.getString("name"));
exam.setUserClassName(jsonObject.getString("userClassName"));
exam.setClassOwnerEmail(jsonObject.getString("classOwnerEmail"));
exam.setFirstGrade(jsonObject.getString("firstGrades"));
exam.setFirstGrades(jsonObject.getString("firstGrades"));

}catch (JSONException | UserException e){
e.printStackTrace();
}

return exam;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
import okhttp3.RequestBody;
import okhttp3.Response;

public class AddFirstGradesPost extends AsyncTask<String, String, String> {
private HashMap<String, String> hashFirstGrades;
public class AddFirstGrades extends AsyncTask<String, String, String> {
private UserClass userClass;
private Exam exam;
private final String url = "https://trezentos-api.herokuapp.com/api/exam/first_grades";

public AddFirstGradesPost(UserClass userClass, Exam exam) {
public AddFirstGrades(UserClass userClass, Exam exam) {
this.userClass = userClass;
this.exam = exam;
}
Expand Down
92 changes: 92 additions & 0 deletions app/src/main/java/fga/mds/gpp/trezentos/DAO/AddSecondGrades.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package fga.mds.gpp.trezentos.DAO;

import android.os.AsyncTask;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

import fga.mds.gpp.trezentos.Model.Exam;
import fga.mds.gpp.trezentos.Model.UserClass;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class AddSecondGrades extends AsyncTask<String, String, String>{
private UserClass userClass;
private Exam exam;
private final String url = "https://trezentos-api.herokuapp.com/api/exam/second_grades";

public AddSecondGrades(UserClass userClass, Exam exam) {
this.userClass = userClass;
this.exam = exam;
}

@Override
protected String doInBackground(String... params) {
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
OkHttpClient client = new OkHttpClient();
String newBodySecondGrades = createBody(userClass, exam);
Log.d("newBody", newBodySecondGrades);

RequestBody body = RequestBody.create(JSON, newBodySecondGrades);
Request request = new Request.Builder()
.url(url)
.put(body)
.build();

try {
Response response = client.newCall(request).execute();
return response.body().string();
} catch (IOException e) {
e.printStackTrace();
Log.i("LOG", "IOException in doInBackground method");
}
return null;
}

public String createBody(UserClass userClass, Exam exam) {

JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("email", exam.getClassOwnerEmail());
Log.d("JSON", exam.getClassOwnerEmail());
} catch (JSONException e) {
Log.d("JSONEXCEPTION", e.toString());
e.printStackTrace();
}
try {
jsonBody.put("userClassName", userClass.getClassName());
Log.d("JSONCLASS", userClass.getClassName());
} catch (JSONException e) {
Log.d("JSONEXCEPTION", e.toString());
e.printStackTrace();
}
try {
jsonBody.put("name", exam.getNameExam());
Log.d("JSON", exam.getNameExam());
} catch (JSONException e) {
Log.d("JSONEXCEPTION", e.toString());
e.printStackTrace();
}
try {
jsonBody.put("secondGrades", exam.getSecondGrades());
Log.d("JSON", exam.getSecondGrades());
} catch (JSONException e) {
Log.d("JSONEXCEPTION", e.toString());
e.printStackTrace();
}

Log.d("JSON", jsonBody.toString());
return jsonBody.toString();
}

@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
}
}
23 changes: 18 additions & 5 deletions app/src/main/java/fga/mds/gpp/trezentos/Model/Exam.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@

import fga.mds.gpp.trezentos.Exception.UserException;
import fga.mds.gpp.trezentos.R;
import java.util.HashMap;

import fga.mds.gpp.trezentos.Exception.UserException;
import fga.mds.gpp.trezentos.View.StudentsFragment;

public class Exam implements Serializable {
private String nameExam;
private String userClassName;
private String classOwnerEmail;
private String firstGrades;
private String firstGrades;
private String secondGrades;

public Exam(){
//An empty constructor is needed to create a new instance of object,
Expand Down Expand Up @@ -43,7 +48,7 @@ public void setNameExam(String nameExam)throws UserException{
}
}

public String getNameExam(){
public String getNameExam() {
return nameExam;
}

Expand All @@ -58,7 +63,7 @@ public void setUserClassName(String userClassName) throws UserException{

}

public String getUserClassName(){
public String getUserClassName() {
return userClassName;
}

Expand All @@ -74,11 +79,19 @@ public String getClassOwnerEmail() {
return classOwnerEmail;
}

public void setFirstGrades(String firstGrades) {
this.firstGrades = firstGrades;
}

public String getFirstGrades() {
return firstGrades;
}

public void setFirstGrade(String firstGrades) {
this.firstGrades = firstGrades;
public void setSecondGrades(String secondGrades) {
this.secondGrades = secondGrades;
}

public String getSecondGrades() {
return secondGrades;
}
}
22 changes: 15 additions & 7 deletions app/src/main/java/fga/mds/gpp/trezentos/View/ExamActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@

public class ExamActivity extends AppCompatActivity {


// private FloatingActionButton floatingActionButton;
private UserClass userClass;
private ViewPager viewPager;
private Toolbar toolbar;
private Exam exam;


@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -87,7 +84,6 @@ public boolean onCreateOptionsMenu(Menu menu){
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item){
int id = item.getItemId();

Expand All @@ -102,7 +98,6 @@ public boolean onOptionsItemSelected(MenuItem item){
Log.d("DATAEXAME", userClass.getClassName());
Log.d("DATAEXAME", exam.getNameExam());
Log.d("DATAEXAME", exam.getClassOwnerEmail());
Log.d("DATAEXAME", exam.getFirstGrades());

try {
userExamControl.validateAddsFirstGrade(userClass, exam);
Expand All @@ -113,13 +108,26 @@ public boolean onOptionsItemSelected(MenuItem item){
} catch (InterruptedException e) {
e.printStackTrace();
}
return true;
}else if(id == R.id.action_update_trezentos_grades) {
UserExamControl userExamControl;
userExamControl = UserExamControl.getInstance(getApplicationContext());

Intent intent = getIntent();
Bundle extras = intent.getExtras();
exam = (Exam) extras.getSerializable("Exam");

try {
userExamControl.addSecondGrade(userClass, exam);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
else if(id == R.id.action_sort_groups){
}
return super.onOptionsItemSelected(item);


}
}

Loading

0 comments on commit 597048f

Please sign in to comment.