- private void apiRequest(String target, String test, final PrivateKey pk, final X509Certificate ce) throws IOException, MalformedURLException, NoSuchAlgorithmException, KeyManagementException, UnsupportedEncodingException, GeneralSecurityException {
- HttpURLConnection connection = (HttpURLConnection) new URL("https://" + getServerName().replaceFirst("^www.", "api.") + CATSImport.PATH).openConnection();
- authenticateClientCert(pk, ce, connection);
- connection.setDoOutput(true);
- OutputStream os = connection.getOutputStream();
- os.write(("serial=" + target + "&variant=" + URLEncoder.encode(test, "UTF-8") + "&date=" + System.currentTimeMillis()).getBytes("UTF-8"));
- System.out.println(connection.getResponseCode());
- System.out.println(connection.getResponseMessage());
+ @Test
+ public void testImportCATSFailures() throws GigiApiException, IOException, GeneralSecurityException, InterruptedException {
+ assertEquals(1, u.getTrainings().length);
+ assertNotEquals(200, executeImportQuery("").getResponseCode());
+ assertNotEquals(200, executeImportQuery("mid=" + u.getId()).getResponseCode());
+ assertNotEquals(200, executeImportQuery("mid=" + u.getId() + "&variant=Test+Training").getResponseCode());
+ assertNotEquals(200, executeImportQuery("mid=" + u.getId() + "&variant=Test+Training&date=" + System.currentTimeMillis()).getResponseCode());
+ assertNotEquals(200, executeImportQuery("mid=" + u.getId() + "&variant=Test+Training&date=" + System.currentTimeMillis() + "&language=en").getResponseCode());
+ assertNotEquals(200, executeImportQuery("mid=" + u.getId() + "&variant=Test+Training&date=" + System.currentTimeMillis() + "&version=1.0").getResponseCode());
+ assertEquals(1, u.getTrainings().length);
+ apiImport(u, "Test Training");
+ assertEquals(2, u.getTrainings().length);
+
+ }
+
+ private void apiImport(User target, String test) throws IOException, MalformedURLException, NoSuchAlgorithmException, KeyManagementException, UnsupportedEncodingException, GeneralSecurityException {
+ HttpURLConnection connection = executeImportQuery("mid=" + target.getId() + "&variant=" + URLEncoder.encode(test, "UTF-8") + "&date=" + System.currentTimeMillis() + "&language=en&version=1.0");
+ if (connection.getResponseCode() != 200) {
+ throw new Error(connection.getResponseMessage());
+ }