User user = applicationManager.getUserService().getUser(testUser.getUsername());
String authnToken = login(user.getUsername(), testUser.getUsername()); // ugh
// just get the first random one
List<Connection> connections = applicationManager.getConnectionService().getConnections(ProjectHostingProvider.TYPE, user);
Connection connection = connections.get(0);
JSONObject json = new JSONObject();
// Just to be sure, let's change the visibility to something valid
json.put("hashtag", random);
makeRequest(connectionsBaseUrl + "/" + connection.getId() + "/hashtag", "POST", json, authnToken);
/// verify the connection is tagged
connection = applicationManager.getConnectionService().getConnection(connection.getId());
assertNotNull(connection.getHashtags());
assertTrue(connection.getHashtags().size() > 0);
assertTrue(connection.getHashtags().contains("#" + random));
// now check the child items
List<InventoryItem> items = applicationManager.getInventoryService().getInventoryItems(connection, user);
assertNotNull(items);
assertTrue(items.size() > 0);
for (InventoryItem item : items) {
assertTrue(item.getHashtags().contains("#" + random));
}
// now delete
makeRequest(connectionsBaseUrl + "/" + connection.getId() + "/hashtag/" + random, "DELETE", null, authnToken);
// get a fresh copy from the db
connection = applicationManager.getConnectionService().getConnection(connection.getId());
assertFalse(connection.getHashtags().contains("#" + random));
// now check the child items
items = applicationManager.getInventoryService().getInventoryItems(connection, user);
for (InventoryItem item : items) {
assertFalse(item.getHashtags().contains("#" + random));