| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| target | ||
| *.iml | ||
| .idea |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| target | ||
| *.iml | ||
| .idea |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| http://hmkcode.com/java-servlet-send-receive-json-using-jquery-ajax/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| [{"title":"bbc","url":"news.bbc.co.uk","categories":["news"],"tags":["uk news"]},{"title":null,"url":"www.google.co.uk","categories":["youtube","gmail","gdrive"],"tags":["search"]}] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| package com.hmkcode;/** | ||
| * Author: wge | ||
| * Date: 22/11/2013 | ||
| * Time: 18:09 | ||
| */ | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.hmkcode.vo.Article; | ||
| import org.junit.Test; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
|
|
||
| public class ArticleMapperTest | ||
| { | ||
| private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(ArticleMapperTest.class.getName()); | ||
|
|
||
|
|
||
| @Test | ||
| public void testValidJson() throws Exception | ||
|
Comment thread
Copy link
Copy Markdown
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Sorry, something went wrong.
All reactions
|
||
| { | ||
| String json = readlineFromResourceFile("/valid.json"); | ||
|
|
||
| ObjectMapper mapper = new ObjectMapper(); | ||
| Article article = mapper.readValue(json, Article.class); | ||
|
|
||
| assert(article.url.equals("news.bbc.co.uk")); | ||
|
Comment thread
Copy link
Copy Markdown
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Sorry, something went wrong.
All reactions
|
||
| assert(article.categories.contains("news")); | ||
| assert(article.categories.size() == 1); | ||
| assert(article.tags.size() == 1); | ||
| assert(article.tags.contains("uk news")); | ||
|
|
||
| List<Article> articles = new ArrayList<Article>(); | ||
| articles.add(article); | ||
|
|
||
| Article extra = new Article(); | ||
| extra.url = "www.google.co.uk"; | ||
| List categoryList = new ArrayList<String>(); | ||
| categoryList.add("youtube"); | ||
| categoryList.add("gmail"); | ||
| categoryList.add("gdrive"); | ||
|
|
||
| extra.categories = categoryList; | ||
| extra.addTag("search"); | ||
|
|
||
| articles.add(extra); | ||
|
|
||
| //this will appear in the root of your project. | ||
| mapper.writeValue(new File("modified.json"), articles); | ||
| } | ||
|
|
||
| @Test (expected=com.fasterxml.jackson.core.JsonParseException.class) | ||
| public void testBadInput() throws Exception | ||
| { | ||
| String json = readlineFromResourceFile("/malformed.json"); | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| Article article = mapper.readValue(json, Article.class); | ||
|
Comment thread
Copy link
Copy Markdown
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Sorry, something went wrong.
All reactions
|
||
| } | ||
|
|
||
| @Test | ||
| public void missingUrl() throws Exception | ||
|
Comment thread
Copy link
Copy Markdown
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Sorry, something went wrong.
All reactions
|
||
| { | ||
| String json = readlineFromResourceFile("/missingUrl.json"); | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| Article article = mapper.readValue(json, Article.class); | ||
| assert(article.url == null); | ||
| assert(article.categories.contains("news")); | ||
| assert(article.categories.size() == 1); | ||
| assert(article.tags.size() == 1); | ||
| assert(article.tags.contains("uk news")); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| String readlineFromResourceFile(String filename) throws IOException | ||
|
Comment thread
Copy link
Copy Markdown
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Sorry, something went wrong.
All reactions
|
||
| { | ||
| InputStream is = getClass().getResourceAsStream(filename); | ||
| byte[] buff = new byte[1000]; | ||
| is.read(buff); | ||
| return new String(buff); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"title":"bbc","url":news.bbc.co.uk,"categories":["news"],"tags":["uk news"]}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"title":"bbc","categories":["news"],"tags":["uk news"]}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"title":"bbc","url":"news.bbc.co.uk","categories":["news"],"tags":["uk news"]}; |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualitySorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.