@Test public void submitFeedbackPostForTextMapHasCorrectValues() throws Exception { List<FeedbackAnswer> answers = new ArrayList<FeedbackAnswer>(); answers.add(new FeedbackAnswer(new FeedbackQuestion(0, "Question", "text"), "Answer")); String url = "mock_url"; String apiUrl = "wee"; when(connectionBuilder.addApiCallQueryParameters(Mockito.anyString())).thenReturn(apiUrl); when(rb.postForText(Mockito.anyString(), anyMap())).thenAnswer(new Answer() { @Override public String answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); Map<String, String> paramMap = (HashMap<String, String>) args[1]; assertEquals(2, paramMap.keySet().size()); assertEquals(2, paramMap.values().size()); assertTrue(paramMap.keySet().contains("answers[0][question_id]")); assertTrue(paramMap.keySet().contains("answers[0][answer]")); assertEquals("0", paramMap.get("answers[0][question_id]")); assertEquals("Answer", paramMap.get("answers[0][answer]")); return ""; } }); server.submitFeedback(url, answers); }
public String submitFeedback(String answerUrl, List<FeedbackAnswer> answers) { final String submitUrl = connectionBuilder.addApiCallQueryParameters(answerUrl); Map<String, String> params = new HashMap<String, String>(); for (int i = 0; i < answers.size(); ++i) { String keyPrefix = "answers[" + i + "]"; FeedbackAnswer answer = answers.get(i); params.put(keyPrefix + "[question_id]", "" + answer.getQuestion().getId()); params.put(keyPrefix + "[answer]", answer.getAnswer()); } try { return connectionBuilder.createConnection().postForText(submitUrl, params); } catch (FailedHttpResponseException e) { return checkForObsoleteClient(e); } catch (Exception e) { throw new RuntimeException("An error occured while submitting feedback: " + e.getMessage()); } }
ServerManager { public String submitFeedback(String answerUrl, List<FeedbackAnswer> answers) { final String submitUrl = connectionBuilder.addApiCallQueryParameters(answerUrl); Map<String, String> params = new HashMap<String, String>(); for (int i = 0; i < answers.size(); ++i) { String keyPrefix = "answers[" + i + "]"; FeedbackAnswer answer = answers.get(i); params.put(keyPrefix + "[question_id]", "" + answer.getQuestion().getId()); params.put(keyPrefix + "[answer]", answer.getAnswer()); } try { return connectionBuilder.createConnection().postForText(submitUrl, params); } catch (FailedHttpResponseException e) { return checkForObsoleteClient(e); } catch (Exception e) { throw new RuntimeException("An error occured while submitting feedback: " + e.getMessage()); } } }
ServerManager { public String submitFeedback(String answerUrl, List<FeedbackAnswer> answers) { final String submitUrl = connectionBuilder.addApiCallQueryParameters(answerUrl); Map<String, String> params = new HashMap<String, String>(); for (int i = 0; i < answers.size(); ++i) { String keyPrefix = "answers[" + i + "]"; FeedbackAnswer answer = answers.get(i); params.put(keyPrefix + "[question_id]", "" + answer.getQuestion().getId()); params.put(keyPrefix + "[answer]", answer.getAnswer()); } try { return connectionBuilder.createConnection().postForText(submitUrl, params); } catch (FailedHttpResponseException e) { return checkForObsoleteClient(e); } catch (Exception e) { throw new RuntimeException("An error occured while submitting feedback: " + e.getMessage()); } } ServerManager(Gson mapper, ConnectionBuilder connectionBuilder, Settings settings);  ServerManager(Settings settings); }
ServerManager { public String submitFeedback(String answerUrl, List<FeedbackAnswer> answers) { final String submitUrl = connectionBuilder.addApiCallQueryParameters(answerUrl); Map<String, String> params = new HashMap<String, String>(); for (int i = 0; i < answers.size(); ++i) { String keyPrefix = "answers[" + i + "]"; FeedbackAnswer answer = answers.get(i); params.put(keyPrefix + "[question_id]", "" + answer.getQuestion().getId()); params.put(keyPrefix + "[answer]", answer.getAnswer()); } try { return connectionBuilder.createConnection().postForText(submitUrl, params); } catch (FailedHttpResponseException e) { return checkForObsoleteClient(e); } catch (Exception e) { throw new RuntimeException("An error occured while submitting feedback: " + e.getMessage()); } } ServerManager(Gson mapper, ConnectionBuilder connectionBuilder, Settings settings);  ServerManager(Settings settings); List<Course> getCourses(); List<Exercise> getExercises(String courseId); ZippedProject getExerciseZip(String zipUrl); SubmissionResponse uploadFile(Exercise exercise, byte[] data); SubmissionResponse uploadFile(Exercise exercise, byte[] data, Map<String, String> extraParams); SubmissionResult getSubmissionResult(URI resultURI); String submitFeedback(String answerUrl, List<FeedbackAnswer> answers); void sendEventLogs(String url, List<LoggableEvent> events); List<Review> downloadReviews(Course course); boolean markReviewAsRead(Review review); }
ServerManager { public String submitFeedback(String answerUrl, List<FeedbackAnswer> answers) { final String submitUrl = connectionBuilder.addApiCallQueryParameters(answerUrl); Map<String, String> params = new HashMap<String, String>(); for (int i = 0; i < answers.size(); ++i) { String keyPrefix = "answers[" + i + "]"; FeedbackAnswer answer = answers.get(i); params.put(keyPrefix + "[question_id]", "" + answer.getQuestion().getId()); params.put(keyPrefix + "[answer]", answer.getAnswer()); } try { return connectionBuilder.createConnection().postForText(submitUrl, params); } catch (FailedHttpResponseException e) { return checkForObsoleteClient(e); } catch (Exception e) { throw new RuntimeException("An error occured while submitting feedback: " + e.getMessage()); } } ServerManager(Gson mapper, ConnectionBuilder connectionBuilder, Settings settings);  ServerManager(Settings settings); List<Course> getCourses(); List<Exercise> getExercises(String courseId); ZippedProject getExerciseZip(String zipUrl); SubmissionResponse uploadFile(Exercise exercise, byte[] data); SubmissionResponse uploadFile(Exercise exercise, byte[] data, Map<String, String> extraParams); SubmissionResult getSubmissionResult(URI resultURI); String submitFeedback(String answerUrl, List<FeedbackAnswer> answers); void sendEventLogs(String url, List<LoggableEvent> events); List<Review> downloadReviews(Course course); boolean markReviewAsRead(Review review);  }