List of usage examples for org.apache.commons.httpclient.methods PostMethod setRequestBody
public void setRequestBody(NameValuePair[] paramArrayOfNameValuePair) throws IllegalArgumentException
From source file:org.iavante.sling.gad.catalog.RevisedServiceIT.java
protected void setUp() { Map<String, String> envs = System.getenv(); Set<String> keys = envs.keySet(); Iterator<String> it = keys.iterator(); boolean hashost = false; while (it.hasNext()) { String key = (String) it.next(); if (key.compareTo(HOSTVAR) == 0) { SLING_URL = SLING_URL + (String) envs.get(key); hashost = true;/*w w w .j av a 2s . c o m*/ } } if (hashost == false) SLING_URL = SLING_URL + HOSTPREDEF; client = new HttpClient(); col_title = "it_col"; content_title = "it_content"; source_title = "it_source"; file = "it.flv"; mimetype = "video/flv"; schema = "default"; title = "Test case content"; schema = "default"; slug_collection = "admin"; slug_content = "it_content"; tags_request = " test, case"; tags_response = "test,case"; tag1_input = "AEIOU"; tag2_input = "Recetas Equilibradas"; tag1_title = "aeiou"; tag2_title = "recetas equilibradas"; tag1_slug = "aeiou"; tag2_slug = "recetas-equilibradas"; defaultcreds = new UsernamePasswordCredentials("admin", "admin"); authPrefs = new ArrayList(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); // Delete the collection System.out.println("Delete collection: " + SLING_URL + COL_URL + col_title); PostMethod post_delete = new PostMethod(SLING_URL + COL_URL + col_title); NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), }; post_delete.setDoAuthentication(true); post_delete.setRequestBody(data_delete); try { client.executeMethod(post_delete); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_delete.releaseConnection(); // Create collection System.out.println("Create collection"); PostMethod post_create_col = new PostMethod(SLING_URL + COL_URL + col_title); post_create_col.setDoAuthentication(true); NameValuePair[] data_create_col = { new NameValuePair("sling:resourceType", "gad/collection"), new NameValuePair("title", col_title), new NameValuePair("schema", schema), new NameValuePair("subtitle", ""), new NameValuePair("extern_storage", "on"), new NameValuePair("picture", ""), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_col.setRequestBody(data_create_col); //post.setDoAuthentication(true); try { client.executeMethod(post_create_col); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Collection created assertEquals(post_create_col.getStatusCode(), 201); post_create_col.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create content in collection System.out.println("Create content in collection"); PostMethod post_create_content = new PostMethod( SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title); post_create_content.setDoAuthentication(true); NameValuePair[] data_create_content = { new NameValuePair("sling:resourceType", "gad/content"), new NameValuePair("title", content_title), new NameValuePair("schema", schema), new NameValuePair("description", "Content description generated by test case. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."), new NameValuePair("author", "Test case"), new NameValuePair("origin", "Test case"), new NameValuePair("lang", "es"), new NameValuePair("tags", tag1_input), new NameValuePair("tags", tag2_input), new NameValuePair("tags@TypeHint", "String[]"), new NameValuePair("state", "pending"), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_content.setRequestBody(data_create_content); //post.setDoAuthentication(true); try { client.executeMethod(post_create_content); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Content created assertEquals(post_create_content.getStatusCode(), 201); post_create_content.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create the source System.out.println("Create source in content"); PostMethod post_create = new PostMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title + "/" + SOURCES_FOLDER + "/" + source_title); System.out.println("Request: " + SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title + "/" + SOURCES_FOLDER + "/" + source_title); post_create.setDoAuthentication(true); NameValuePair[] data_create = { new NameValuePair("sling:resourceType", "gad/source"), new NameValuePair("title", source_title), new NameValuePair("file", ""), new NameValuePair("mimetype", ""), new NameValuePair("text_encoding", ""), new NameValuePair("lang", ""), new NameValuePair("length", ""), new NameValuePair("size", ""), new NameValuePair("type", ""), new NameValuePair("bitrate", ""), new NameValuePair("tags", ""), new NameValuePair("tracks_number", ""), new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""), new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""), new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create.setRequestBody(data_create); //post.setDoAuthentication(true); try { client.executeMethod(post_create); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(post_create.getStatusCode(), 201); post_create.releaseConnection(); try { Thread.sleep(5000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Send the content to revision System.out.println("Send the content to revision"); PostMethod post_send_to_revision = new PostMethod( SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title); String catalog_pending_url = CATALOG_URL + PENDING_FOLDER + "/"; System.out.println("Catalog url: " + catalog_pending_url); System.out.println("Send to revision: " + SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title); post_send_to_revision.setDoAuthentication(true); NameValuePair[] data_send_to_revision = { new NameValuePair(":operation", "copy"), new NameValuePair(":dest", catalog_pending_url), new NameValuePair("replace", "true") }; post_send_to_revision.setRequestBody(data_send_to_revision); try { client.executeMethod(post_send_to_revision); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(post_send_to_revision.getStatusCode(), 201); post_send_to_revision.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Revise the content System.out.println("Revise the content"); PostMethod post_revise_content = new PostMethod( SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title); String catalog_revised_url = CATALOG_URL + REVISED_FOLDER + "/"; System.out.println("Revise content: " + SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title); post_send_to_revision.setDoAuthentication(true); NameValuePair[] data_revise_content = { new NameValuePair(":operation", "move"), new NameValuePair(":dest", catalog_revised_url), new NameValuePair("replace", "true") }; post_revise_content.setRequestBody(data_revise_content); try { client.executeMethod(post_revise_content); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(post_revise_content.getStatusCode(), 201); post_revise_content.releaseConnection(); }
From source file:org.iavante.sling.gad.catalog.RevisedServiceIT.java
protected void tearDown() { try {//w ww . ja v a2 s. c om Thread.sleep(9000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Delete the collection System.out.println("Deleting collection"); PostMethod post_delete = new PostMethod(SLING_URL + COL_URL + col_title); NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), }; post_delete.setDoAuthentication(true); post_delete.setRequestBody(data_delete); try { client.executeMethod(post_delete); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(post_delete.getStatusCode(), 200); post_delete.releaseConnection(); // Delete revision PostMethod post_delete_rev = new PostMethod(SLING_URL + CATALOG_URL + REVISED_FOLDER + "/" + content_title); NameValuePair[] data_delete_rev = { new NameValuePair(":operation", "delete"), }; post_delete_rev.setDoAuthentication(true); post_delete_rev.setRequestBody(data_delete_rev); try { client.executeMethod(post_delete_rev); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(post_delete_rev.getStatusCode(), 200); post_delete_rev.releaseConnection(); // Delete tags PostMethod post_delete_tag1 = new PostMethod(SLING_URL + CATALOG_URL + TAGS_FOLDER + "/" + tag1_slug); NameValuePair[] data_delete_tag1 = { new NameValuePair(":operation", "delete"), }; post_delete_tag1.setDoAuthentication(true); post_delete_tag1.setRequestBody(data_delete_tag1); try { client.executeMethod(post_delete_tag1); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(post_delete_tag1.getStatusCode(), 200); post_delete_tag1.releaseConnection(); PostMethod post_delete_tag2 = new PostMethod(SLING_URL + CATALOG_URL + TAGS_FOLDER + "/" + tag2_slug); NameValuePair[] data_delete_tag2 = { new NameValuePair(":operation", "delete"), }; post_delete_tag2.setDoAuthentication(true); post_delete_tag2.setRequestBody(data_delete_tag2); try { client.executeMethod(post_delete_tag2); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(post_delete_tag2.getStatusCode(), 200); post_delete_tag2.releaseConnection(); }
From source file:org.iavante.sling.gad.channel.ChannelServiceIT.java
@org.junit.Before protected void setUp() { Map<String, String> envs = System.getenv(); Set<String> keys = envs.keySet(); Iterator<String> it = keys.iterator(); boolean hashost = false; while (it.hasNext()) { String key = (String) it.next(); if (key.compareTo(HOSTVAR) == 0) { SLING_URL = SLING_URL + (String) envs.get(key); hashost = true;//from w ww .ja va2 s. c o m } } if (hashost == false) SLING_URL = SLING_URL + HOSTPREDEF; client = new HttpClient(); col_title = "it_col"; content_title = "it_content"; source_title = "it_source"; file = "it_for_channel_tests.mpeg"; mimetype = "video/flv"; schema = "default"; title = "Test case content"; schema = "default"; slug_collection = "admin"; slug_content = "it_content"; tags_request = " test, case"; tags_response = "test,case"; channel_title = "IT Channel"; channel_slug = "it_channel"; channel_subtitle = "it_channel"; channel_schema = "default"; channel_distribution_format = "preview"; channel_distribution_server = "s3"; source_default_slug = "fuente_default"; tag1_input = "AEIOU"; tag2_input = "Recetas Equilibradas"; tag1_title = "aeiou"; tag2_title = "recetas equilibradas"; tag1_slug = "aeiou"; tag2_slug = "recetas-equilibradas"; defaultcreds = new UsernamePasswordCredentials("admin", "admin"); authPrefs = new ArrayList(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); // Delete the collection PostMethod post_delete = new PostMethod(SLING_URL + COL_URL + col_title); NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), }; post_delete.setDoAuthentication(true); post_delete.setRequestBody(data_delete); try { client.executeMethod(post_delete); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_delete.releaseConnection(); // Create collection PostMethod post_create_col = new PostMethod(SLING_URL + COL_URL + col_title); post_create_col.setDoAuthentication(true); NameValuePair[] data_create_col = { new NameValuePair("sling:resourceType", "gad/collection"), new NameValuePair("title", col_title), new NameValuePair("schema", schema), new NameValuePair("subtitle", ""), new NameValuePair("extern_storage", "on"), new NameValuePair("picture", ""), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_col.setRequestBody(data_create_col); // post.setDoAuthentication(true); try { client.executeMethod(post_create_col); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Collection created assertEquals(201, post_create_col.getStatusCode()); post_create_col.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create content in collection PostMethod post_create_content = new PostMethod( SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title); post_create_content.setDoAuthentication(true); NameValuePair[] data_create_content = { new NameValuePair("sling:resourceType", "gad/content"), new NameValuePair("title", content_title), new NameValuePair("schema", schema), new NameValuePair("description", "Content description generated by test case. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."), new NameValuePair("author", "Test case"), new NameValuePair("origin", "Test case"), new NameValuePair("lang", "es"), new NameValuePair("tags@TypeHint", "String[]"), new NameValuePair("tags", tag1_input), new NameValuePair("tags", tag2_input), new NameValuePair("state", "pending"), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_content.setRequestBody(data_create_content); try { client.executeMethod(post_create_content); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Content created assertEquals(201, post_create_content.getStatusCode()); post_create_content.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create the source PostMethod post_create = new PostMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title + "/" + SOURCES_FOLDER + "/" + source_title); post_create.setDoAuthentication(true); NameValuePair[] data_create = { new NameValuePair("sling:resourceType", "gad/source"), new NameValuePair("title", source_title), new NameValuePair("file", file), new NameValuePair("mimetype", ""), new NameValuePair("text_encoding", ""), new NameValuePair("lang", ""), new NameValuePair("length", ""), new NameValuePair("size", ""), new NameValuePair("type", ""), new NameValuePair("bitrate", ""), new NameValuePair("tags", ""), new NameValuePair("tracks_number", ""), new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""), new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""), new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create.setRequestBody(data_create); try { client.executeMethod(post_create); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_create.getStatusCode()); post_create.releaseConnection(); try { Thread.sleep(5000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Send the content to revision PostMethod post_send_to_revision = new PostMethod( SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title); String catalog_pending_url = CATALOG_URL + PENDING_FOLDER + "/"; post_send_to_revision.setDoAuthentication(true); NameValuePair[] data_send_to_revision = { new NameValuePair(":operation", "copy"), new NameValuePair(":dest", catalog_pending_url), new NameValuePair("replace", "true") }; post_send_to_revision.setRequestBody(data_send_to_revision); try { client.executeMethod(post_send_to_revision); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_send_to_revision.getStatusCode()); post_send_to_revision.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Revise the content PostMethod post_revise_content = new PostMethod( SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title); String catalog_revised_url = CATALOG_URL + REVISED_FOLDER + "/"; post_send_to_revision.setDoAuthentication(true); NameValuePair[] data_revise_content = { new NameValuePair(":operation", "move"), new NameValuePair(":dest", catalog_revised_url), new NameValuePair("replace", "true") }; post_revise_content.setRequestBody(data_revise_content); try { client.executeMethod(post_revise_content); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_revise_content.getStatusCode()); post_revise_content.releaseConnection(); // Create channel PostMethod post_create_channel = new PostMethod(SLING_URL + CHANNEL_URL + channel_slug); post_create_channel.setDoAuthentication(true); NameValuePair[] data_create_channel = { new NameValuePair("sling:resourceType", "gad/channel"), new NameValuePair("title", channel_title), new NameValuePair("schema", channel_schema), new NameValuePair("distribution_format", channel_distribution_format), new NameValuePair("distribution_server", channel_distribution_server), new NameValuePair("subtitle", channel_subtitle), new NameValuePair("picture", ""), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", ""), new NameValuePair("distribution_server_config", "{'test_prop': 'test_value'}") }; post_create_channel.setRequestBody(data_create_channel); try { client.executeMethod(post_create_channel); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_create_channel.releaseConnection(); try { Thread.sleep(4000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Publish the content PostMethod post_publish = new PostMethod(SLING_URL + CATALOG_URL + REVISED_FOLDER + "/" + content_title); String channel = CHANNEL_URL + channel_slug + "/contents/"; post_publish.setDoAuthentication(true); NameValuePair[] data_publish = { new NameValuePair(":operation", "copy"), new NameValuePair(":dest", channel), new NameValuePair("replace", "true") }; post_publish.setRequestBody(data_publish); try { client.executeMethod(post_publish); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_publish.getStatusCode()); post_publish.releaseConnection(); }
From source file:org.iavante.sling.gad.channel.ChannelServiceIT.java
@org.junit.After protected void tearDown() { try {/* w w w .j a va2 s . c o m*/ Thread.sleep(4000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Delete the collection PostMethod post_delete = new PostMethod(SLING_URL + COL_URL + col_title); NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), }; post_delete.setDoAuthentication(true); post_delete.setRequestBody(data_delete); try { client.executeMethod(post_delete); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(200, post_delete.getStatusCode()); post_delete.releaseConnection(); try { Thread.sleep(4000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Delete revision PostMethod post_delete_rev = new PostMethod(SLING_URL + CATALOG_URL + REVISED_FOLDER + "/" + content_title); NameValuePair[] data_delete_rev = { new NameValuePair(":operation", "delete"), }; post_delete_rev.setDoAuthentication(true); post_delete_rev.setRequestBody(data_delete_rev); try { client.executeMethod(post_delete_rev); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_delete_rev.releaseConnection(); try { Thread.sleep(4000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Delete the channel PostMethod post_delete_channel = new PostMethod(SLING_URL + CHANNEL_URL + channel_slug); NameValuePair[] data_delete_channel = { new NameValuePair(":operation", "delete"), }; post_delete_channel.setDoAuthentication(true); post_delete_channel.setRequestBody(data_delete_channel); try { client.executeMethod(post_delete_channel); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_delete_channel.releaseConnection(); }
From source file:org.iavante.sling.gad.channel.ChannelServiceIT.java
@org.junit.Test public void test_voteContent() { try {/* w w w . j a va 2 s . c o m*/ Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Post vote PostMethod post_vote = new PostMethod( SLING_URL + CHANNEL_URL + channel_slug + "/" + CONTENTS_FOLDER + "/" + content_title); post_vote.setDoAuthentication(true); NameValuePair[] data_publish = { new NameValuePair("addvote", "5") }; post_vote.setRequestBody(data_publish); try { client.executeMethod(post_vote); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } assertEquals(200, post_vote.getStatusCode()); }
From source file:org.iavante.sling.gad.channel.ChannelServiceIT.java
@org.junit.Test public void test_unpublish_revision() { try {/* w w w . ja v a 2s.com*/ Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Unpublish the content PostMethod post_publish = new PostMethod( SLING_URL + CHANNEL_URL + channel_slug + "/" + CONTENTS_FOLDER + "/" + content_title); String unpublished_dest = CHANNEL_URL + channel_slug + "/" + UNPUBLISHED_FOLDER + "/"; post_publish.setDoAuthentication(true); NameValuePair[] data_publish = { new NameValuePair(":operation", "move"), new NameValuePair(":dest", unpublished_dest), new NameValuePair("replace", "true") }; post_publish.setRequestBody(data_publish); try { client.executeMethod(post_publish); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_publish.getStatusCode()); post_publish.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Get the unpublished revision in contents folder HttpMethod get_unpublished_revision = new GetMethod( SLING_URL + CHANNEL_URL + channel_slug + "/" + CONTENTS_FOLDER + "/" + content_title); try { client.executeMethod(get_unpublished_revision); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } assertEquals(404, get_unpublished_revision.getStatusCode()); get_unpublished_revision.releaseConnection(); // Get the unpublished revision in unpublished folder get_unpublished_revision = new GetMethod( SLING_URL + CHANNEL_URL + channel_slug + "/" + UNPUBLISHED_FOLDER + "/" + content_title); try { client.executeMethod(get_unpublished_revision); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } assertEquals(200, get_unpublished_revision.getStatusCode()); get_unpublished_revision.releaseConnection(); try { Thread.sleep(6000); } catch (InterruptedException e1) { e1.printStackTrace(); } String unpublished_state = "unpublished"; HttpMethod get_ref_content_state = new GetMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title + "/" + LOG_FOLDER + "/state"); try { this.client.executeMethod(get_ref_content_state); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // handle response. String response_body = ""; try { response_body = get_ref_content_state.getResponseBodyAsString(); } catch (IOException e) { e.printStackTrace(); } assertEquals(unpublished_state, response_body); get_ref_content_state.releaseConnection(); }
From source file:org.iavante.sling.gad.channel.ChannelServiceIT.java
@org.junit.Test public void test_vote_figures() throws IOException { try {/* w w w .j a va 2s .com*/ Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Post vote PostMethod post_vote = new PostMethod( SLING_URL + CHANNEL_URL + channel_slug + "/" + CONTENTS_FOLDER + "/" + content_title); post_vote.setDoAuthentication(true); NameValuePair[] data_publish = { new NameValuePair("sling:resourceType", "gad/revision"), new NameValuePair("addvote", "5") }; post_vote.setRequestBody(data_publish); try { client.executeMethod(post_vote); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } assertEquals(200, post_vote.getStatusCode()); post_vote.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Post vote PostMethod post_vote2 = new PostMethod( SLING_URL + CHANNEL_URL + channel_slug + "/" + CONTENTS_FOLDER + "/" + content_title); post_vote2.setDoAuthentication(true); NameValuePair[] data_publish2 = { new NameValuePair("sling:resourceType", "gad/revision"), new NameValuePair("addvote", "5") }; post_vote2.setRequestBody(data_publish2); try { client.executeMethod(post_vote2); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } assertEquals(200, post_vote2.getStatusCode()); post_vote2.releaseConnection(); try { Thread.sleep(4000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Get the revision view. Increment visits GetMethod get_voted_content = new GetMethod( SLING_URL + CHANNEL_URL + channel_slug + "/" + CONTENTS_FOLDER + "/" + content_title); try { client.executeMethod(get_voted_content); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String response_body = ""; try { response_body = get_voted_content.getResponseBodyAsString(); } catch (IOException e) { e.printStackTrace(); } assert (response_body.contains("<number>2</number>")); assert (response_body.contains("<sum>10</sum>")); try { Thread.sleep(4000); } catch (InterruptedException e1) { e1.printStackTrace(); } get_voted_content.releaseConnection(); // Get the revision votes. No increment hits counter GetMethod get_content_vote_figures = new GetMethod(SLING_URL + CHANNEL_URL + channel_slug + "/" + CONTENTS_FOLDER + "/" + content_title + "/?onlyvotes=true"); try { client.executeMethod(get_content_vote_figures); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } response_body = ""; try { response_body = get_content_vote_figures.getResponseBodyAsString(); } catch (IOException e) { e.printStackTrace(); } assert (response_body.contains("<number>2</number>")); assert (response_body.contains("<sum>10</sum>")); get_content_vote_figures.releaseConnection(); }
From source file:org.iavante.sling.gad.channel.ChannelToolsIT.java
@org.junit.Before protected void setUp() { Map<String, String> envs = System.getenv(); Set<String> keys = envs.keySet(); Iterator<String> it = keys.iterator(); boolean hashost = false; while (it.hasNext()) { String key = (String) it.next(); if (key.compareTo(HOSTVAR) == 0) { SLING_URL = SLING_URL + (String) envs.get(key); hashost = true;/* w w w . j a v a2s .c om*/ } } if (hashost == false) SLING_URL = SLING_URL + HOSTPREDEF; client = new HttpClient(); col_title = "it_col"; content_title = "it_content"; source_title = "it_source"; file = "it_for_channel_tests.mpeg"; mimetype = "video/flv"; schema = "default"; title = "Test case content"; schema = "default"; slug_collection = "admin"; slug_content = "it_content"; tags_request = " test, case"; tags_response = "test,case"; channel_title = "IT Channel"; channel_slug = "it_channel"; channel_subtitle = "it_channel"; channel_schema = "default"; channel_distribution_format = "ies_web_medium,preview"; channel_distribution_server = "s3"; source_default_slug = "fuente_default"; tag1_input = "AEIOU"; tag2_input = "Recetas Equilibradas"; tag1_title = "aeiou"; tag2_title = "recetas equilibradas"; tag1_slug = "aeiou"; tag2_slug = "recetas-equilibradas"; defaultcreds = new UsernamePasswordCredentials("admin", "admin"); file_trans_preview = "file_preview.flv"; file_trans_ies = "file_ies.flv"; authPrefs = new ArrayList(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); // Delete the collection PostMethod post_delete = new PostMethod(SLING_URL + COL_URL + col_title); NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), }; post_delete.setDoAuthentication(true); post_delete.setRequestBody(data_delete); try { client.executeMethod(post_delete); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_delete.releaseConnection(); // Create collection PostMethod post_create_col = new PostMethod(SLING_URL + COL_URL + col_title); post_create_col.setDoAuthentication(true); NameValuePair[] data_create_col = { new NameValuePair("sling:resourceType", "gad/collection"), new NameValuePair("title", col_title), new NameValuePair("schema", schema), new NameValuePair("subtitle", ""), new NameValuePair("extern_storage", "on"), new NameValuePair("picture", ""), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_col.setRequestBody(data_create_col); // post.setDoAuthentication(true); try { client.executeMethod(post_create_col); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Collection created assertEquals(201, post_create_col.getStatusCode()); post_create_col.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create content in collection PostMethod post_create_content = new PostMethod( SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title); post_create_content.setDoAuthentication(true); NameValuePair[] data_create_content = { new NameValuePair("sling:resourceType", "gad/content"), new NameValuePair("title", content_title), new NameValuePair("schema", schema), new NameValuePair("description", "Content description generated by test case. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."), new NameValuePair("author", "Test case"), new NameValuePair("origin", "Test case"), new NameValuePair("lang", "es"), new NameValuePair("tags@TypeHint", "String[]"), new NameValuePair("tags", tag1_input), new NameValuePair("tags", tag2_input), new NameValuePair("state", "pending"), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_content.setRequestBody(data_create_content); try { client.executeMethod(post_create_content); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Content created assertEquals(201, post_create_content.getStatusCode()); post_create_content.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create the source PostMethod post_create = new PostMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title + "/" + SOURCES_FOLDER + "/" + source_title); post_create.setDoAuthentication(true); NameValuePair[] data_create = { new NameValuePair("sling:resourceType", "gad/source"), new NameValuePair("title", source_title), new NameValuePair("file", file), new NameValuePair("mimetype", ""), new NameValuePair("text_encoding", ""), new NameValuePair("lang", ""), new NameValuePair("length", ""), new NameValuePair("size", ""), new NameValuePair("type", ""), new NameValuePair("bitrate", ""), new NameValuePair("tags", ""), new NameValuePair("tracks_number", ""), new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""), new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""), new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create.setRequestBody(data_create); try { client.executeMethod(post_create); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_create.getStatusCode()); post_create.releaseConnection(); try { Thread.sleep(5000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create transformation try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create the trans preview preview PostMethod post_create_trans = new PostMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title + "/" + SOURCES_FOLDER + "/fuente_default/transformations/preview"); post_create.setDoAuthentication(true); NameValuePair[] data_create_trans = { new NameValuePair("sling:resourceType", "gad/transformation"), new NameValuePair("file", file_trans_preview) }; post_create_trans.setRequestBody(data_create_trans); try { client.executeMethod(post_create_trans); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_create_trans.getStatusCode()); post_create_trans.releaseConnection(); try { Thread.sleep(5000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create transformation try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create the trans ies PostMethod post_create_trans2 = new PostMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title + "/" + SOURCES_FOLDER + "/fuente_default/transformations/ies_web_medium"); post_create.setDoAuthentication(true); NameValuePair[] data_create_trans2 = { new NameValuePair("sling:resourceType", "gad/transformation"), new NameValuePair("file", file_trans_ies) }; post_create_trans2.setRequestBody(data_create_trans2); try { client.executeMethod(post_create_trans2); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // assertEquals(201,post_create_trans2.getStatusCode()); post_create_trans2.releaseConnection(); try { Thread.sleep(5000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Send the content to revision PostMethod post_send_to_revision = new PostMethod( SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title); String catalog_pending_url = CATALOG_URL + PENDING_FOLDER + "/"; post_send_to_revision.setDoAuthentication(true); NameValuePair[] data_send_to_revision = { new NameValuePair(":operation", "copy"), new NameValuePair(":dest", catalog_pending_url), new NameValuePair("replace", "true") }; post_send_to_revision.setRequestBody(data_send_to_revision); try { client.executeMethod(post_send_to_revision); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_send_to_revision.getStatusCode()); post_send_to_revision.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Revise the content PostMethod post_revise_content = new PostMethod( SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title); String catalog_revised_url = CATALOG_URL + REVISED_FOLDER + "/"; post_send_to_revision.setDoAuthentication(true); NameValuePair[] data_revise_content = { new NameValuePair(":operation", "move"), new NameValuePair(":dest", catalog_revised_url), new NameValuePair("replace", "true") }; post_revise_content.setRequestBody(data_revise_content); try { client.executeMethod(post_revise_content); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_revise_content.getStatusCode()); post_revise_content.releaseConnection(); // Create channel PostMethod post_create_channel = new PostMethod(SLING_URL + CHANNEL_URL + channel_slug); post_create_channel.setDoAuthentication(true); NameValuePair[] data_create_channel = { new NameValuePair("sling:resourceType", "gad/channel"), new NameValuePair("title", channel_title), new NameValuePair("schema", channel_schema), new NameValuePair("distribution_server_config", "{'bucket':'test', 'public_read':'1'}"), new NameValuePair("distribution_format_video", channel_distribution_format), new NameValuePair("distribution_format_image", "preview"), new NameValuePair("distribution_server", channel_distribution_server), new NameValuePair("subtitle", channel_subtitle), new NameValuePair("picture", ""), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", ""), }; post_create_channel.setRequestBody(data_create_channel); try { client.executeMethod(post_create_channel); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_create_channel.releaseConnection(); try { Thread.sleep(5000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Publish the content PostMethod post_publish = new PostMethod(SLING_URL + CATALOG_URL + REVISED_FOLDER + "/" + content_title); String channel = CHANNEL_URL + channel_slug + "/contents/"; post_publish.setDoAuthentication(true); NameValuePair[] data_publish = { new NameValuePair(":operation", "copy"), new NameValuePair(":dest", channel), new NameValuePair("replace", "true") }; post_publish.setRequestBody(data_publish); try { client.executeMethod(post_publish); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_publish.getStatusCode()); post_publish.releaseConnection(); }
From source file:org.iavante.sling.gad.channel.ChannelToolsIT.java
@org.junit.After protected void tearDown() { try {/*from w ww.j a v a 2 s. c o m*/ Thread.sleep(4000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Delete the collection PostMethod post_delete = new PostMethod(SLING_URL + COL_URL + col_title); NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), }; post_delete.setDoAuthentication(true); post_delete.setRequestBody(data_delete); try { client.executeMethod(post_delete); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(200, post_delete.getStatusCode()); post_delete.releaseConnection(); try { Thread.sleep(4000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Delete revision PostMethod post_delete_rev = new PostMethod(SLING_URL + CATALOG_URL + REVISED_FOLDER + "/" + content_title); NameValuePair[] data_delete_rev = { new NameValuePair(":operation", "delete"), }; post_delete_rev.setDoAuthentication(true); post_delete_rev.setRequestBody(data_delete_rev); try { client.executeMethod(post_delete_rev); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_delete_rev.releaseConnection(); try { Thread.sleep(4000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Delete channel PostMethod post_delete_channel = new PostMethod(SLING_URL + CHANNEL_URL + channel_slug); NameValuePair[] data_delete_channel = { new NameValuePair(":operation", "delete"), }; post_delete_channel.setDoAuthentication(true); post_delete_channel.setRequestBody(data_delete_channel); try { client.executeMethod(post_delete_channel); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_delete_channel.releaseConnection(); try { Thread.sleep(4000); } catch (InterruptedException e1) { e1.printStackTrace(); } }
From source file:org.iavante.sling.gad.channel.ChannelToolsIT.java
@org.junit.Test public void test_get_channel_embed_request() { try {// w w w . j a v a 2s .c o m Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Get the revision GetMethod get_revision_simple = new GetMethod( SLING_URL + CHANNEL_URL + channel_slug + "/" + CONTENTS_FOLDER + "/" + content_title); try { client.executeMethod(get_revision_simple); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String body = ""; try { body = get_revision_simple.getResponseBodyAsString(); } catch (IOException e) { e.printStackTrace(); } assertTrue(body.contains("width='400'")); assertTrue(body.contains("height='400'")); // Edit ds custom props PostMethod post_edit_channel = new PostMethod( SLING_URL + CHANNEL_URL + channel_slug + "/" + DS_CUSTOM_PROPS_FOLDER); post_edit_channel.setDoAuthentication(true); NameValuePair[] data_edit_channel = { new NameValuePair("player_width", "1000"), new NameValuePair("player_height", "800") }; new NameValuePair("player_playlist_layout", "top"); post_edit_channel.setRequestBody(data_edit_channel); try { client.executeMethod(post_edit_channel); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_edit_channel.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Get the revision GetMethod get_revision = new GetMethod( SLING_URL + CHANNEL_URL + channel_slug + "/" + CONTENTS_FOLDER + "/" + content_title); try { client.executeMethod(get_revision); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } body = ""; try { body = get_revision.getResponseBodyAsString(); } catch (IOException e) { e.printStackTrace(); } assertTrue(body.contains("width='1000'")); assertTrue(body.contains("height='800'")); assertTrue(body.contains("playlist=none")); get_revision.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Get the revision GetMethod get_revision_override = new GetMethod( SLING_URL + CHANNEL_URL + channel_slug + "/" + CONTENTS_FOLDER + "/" + content_title); NameValuePair[] get_params = { new NameValuePair("player_width", "200"), new NameValuePair("player_height", "200"), new NameValuePair("player_repeat", "true"), new NameValuePair("player_playlist_layout", "left"), new NameValuePair("player_autostart", "true") }; get_revision_override.setQueryString(get_params); try { client.executeMethod(get_revision_override); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } body = ""; try { body = get_revision_override.getResponseBodyAsString(); } catch (IOException e) { e.printStackTrace(); } assertTrue(body.contains("width='200'")); assertTrue(body.contains("height='200'")); assertTrue(body.contains("repeat=true")); assertTrue(body.contains("playlist=left")); assertTrue(body.contains("autostart=true")); get_revision_override.releaseConnection(); }