VirgilCardClient implements CardClient { public RawSignedModel publishCard(RawSignedModel rawCard, String token) throws VirgilServiceException { try { URL url = serviceUrl; String body = rawCard.exportAsJson(); return httpClient.execute(url, "POST", token, new ByteArrayInputStream(ConvertionUtils.toBytes(body)), RawSignedModel.class); } catch (VirgilServiceException e) { LOGGER.log(Level.SEVERE, "Some service issue occurred during request executing", e); throw e; } catch (Exception e) { LOGGER.log(Level.SEVERE, "Some issue occurred during request executing", e); throw new VirgilCardServiceException(e); } } VirgilCardClient();  VirgilCardClient(HttpClient httpClient);  VirgilCardClient(String serviceUrl);  VirgilCardClient(String serviceUrl, HttpClient httpClient);  VirgilCardClient(URL serviceUrl);  VirgilCardClient(URL serviceUrl, HttpClient httpClient); Tuple<RawSignedModel, Boolean> getCard(String cardId, String token); @Override List<String> getOutdated(Collection<String> cardIds, String token); HttpClient getHttpClient(); URL getServiceUrl(); RawSignedModel publishCard(RawSignedModel rawCard, String token); List<RawSignedModel> searchCards(String identity, String token); List<RawSignedModel> searchCards(Collection<String> identities, String token); void revokeCard(String cardId, String token); void setHttpClient(HttpClient httpClient);  }
@Test public void stc_25_publish() throws CryptoException { String identity = Generator.identity(); try { cardClient.publishCard(mocker.generateCardModel(identity), mocker.generateFakeAccessToken(identity).stringRepresentation()); fail(); } catch (VirgilServiceException e) { assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, e.getHttpError().getCode()); assertEquals(20303, e.getErrorCode()); } }
@Test public void stc_27() throws CryptoException { String identity = Generator.identity(); String identitySecond = Generator.identity(); try { cardClient.publishCard(mocker.generateCardModel(identity), mocker.generateAccessToken(identitySecond).stringRepresentation()); fail(); } catch (VirgilServiceException e) { assertEquals(40034, e.getErrorCode()); } }
@Test public void validTokenPublish() throws CryptoException, VirgilServiceException { String identity = Generator.identity(); RawSignedModel cardModelBeforePublish = mocker.generateCardModel(identity); RawSignedModel cardModelAfterPublish = cardClient.publishCard(cardModelBeforePublish, mocker.generateAccessToken(identity).stringRepresentation()); TestUtils.assertCardModelsEquals(cardModelBeforePublish, cardModelAfterPublish); }