Java Code Examples for org.json.simple.parser.ParseException

The following are top voted examples for showing how to use org.json.simple.parser.ParseException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: JHearthstone   File: Card.java   View source code 6 votes vote down vote up
public Card(String n) throws ParseException{
	reader = new JSonReader(new File(GetExecutionPath()).getParent() + "/all-cards.json");
	name = n;
	cost =  (int)(reader.getCost(n));
	attack = (int)(reader.getAttack(n));
	health = (int)(reader.getHealth(n));
	setRarity(JSonReader.getRarity(n));
	set = JSonReader.getSet(n);
	canAttack = false;
	//effects = reader.getEffects(n);
	attributes = reader.getAttributes(n);
	type = reader.getType(n);
	attribute_values = reader.getAttributeValues(n, type);
	triggers = reader.getTriggers(n, type);
	trigger_object = reader.getTriggerObject(n, type);
	hasTaunt = attributes.contains("TAUNT");
	hasDivineShield = attributes.contains("DIVINE_SHIELD");
	hasWindfury = attributes.contains("WINDFURY");
	containsAura = reader.hasAura(n);
	race = reader.getRace(n, type);
}
 
Example 2
Project: JHearthstone   File: Card.java   View source code 6 votes vote down vote up
public Card(String n, String t) throws ParseException{
	reader = new JSonReader(new File(GetExecutionPath()).getParent() + "/all-cards.json");
	name = n;
	cost =  (int)(reader.getCost(n, t));
	attack = (int)(reader.getAttack(n, t));
	health = (int)(reader.getHealth(n, t));
	setRarity(JSonReader.getRarity(n, t));
	set = JSonReader.getSet(n, t);
	canAttack = false;
	//effects = reader.getEffects(n);
	attributes = reader.getAttributes(n, t);
	attribute_values = reader.getAttributeValues(n, t);
	triggers = reader.getTriggers(n, t);
	trigger_object = reader.getTriggerObject(n, t);
	type = t;
	hasTaunt = attributes.contains("TAUNT");
	hasDivineShield = attributes.contains("DIVINE_SHIELD");
	hasWindfury = attributes.contains("WINDFURY");
	containsAura = reader.hasAura(n, t);
	race = reader.getRace(n, t);
}
 
Example 3
Project: talchain   File: GitHubStateTest.java   View source code 6 votes vote down vote up
@Test // testing full suite
public void testRandomStateGitHub() throws ParseException, IOException {

    String sha = "99db6f4f5fea3aa5cfbe8436feba8e213d06d1e8";
    List<String> fileNames = JSONReader.getFileNamesForTreeSha(sha);
    List<String> includedFiles =
            Arrays.asList(
                    "st201504081841JAVA.json",
                    "st201504081842JAVA.json",
                    "st201504081843JAVA.json"
            );

    for (String fileName : fileNames) {
        if (includedFiles.contains(fileName)) {
          System.out.println("Running: " + fileName);
          String json = JSONReader.loadJSON("StateTests//RandomTests/" + fileName);
          GitHubJSONTestSuite.runStateTest(json);
        }
    }

}
 
Example 4
Project: Parabot-317-API-Minified-PkHonor   File: Items.java   View source code 6 votes vote down vote up
public static String getName(int id) {
    String name;
    if ((name = names.get(id)) != null) {
        return name;
    } else {
        try {
            String content = WebUtil.getContents(Configuration.ITEM_API + id);
            if (content.length() > 0) {
                JSONObject jsonObject      = (JSONObject) jsonParser.parse(content);
                JSONObject itemInformation = (JSONObject) jsonObject.get("result");
                if (itemInformation.get("name") != null && !((String) itemInformation.get("name")).equalsIgnoreCase("null")) {
                    name = (String) itemInformation.get("name");
                    names.put(id, name);
                    return name;
                }
            }
        } catch (MalformedURLException | ParseException e) {
            e.printStackTrace();
        }
    }

    return null;
}
 
Example 5
Project: legendarybot   File: IlvlCommand.java   View source code 6 votes vote down vote up
public long getM15(String json) throws ParseException {
    long m15 = 0;
    if (json != null) {
        JSONParser parser = new JSONParser();
        JSONObject battleNetCharacter = (JSONObject) parser.parse(json);
        JSONObject achivements = (JSONObject) battleNetCharacter.get("achievements");
        JSONArray criteriaObject = (JSONArray) achivements.get("criteria");
        int criteriaNumber = -1;
        for (int i = 0; i < criteriaObject.size(); i++) {
            if ((long)criteriaObject.get(i) == 32028    ) {
                criteriaNumber = i;
            }
        }

        if (criteriaNumber != -1) {
            m15 = (long) ((JSONArray)achivements.get("criteriaQuantity")).get(criteriaNumber);
            if (m15 >= 1) {
                m15 += 1;
            }
        }
    }
    return m15;
}
 
Example 6
Project: alfresco-remote-api   File: SubscriptionServiceFollowsPost.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
public JSONArray executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException,
        ParseException
{
    JSONArray jsonUsers = (JSONArray) JSONValue.parseWithException(req.getContent().getContent());

    JSONArray result = new JSONArray();

    for (Object o : jsonUsers)
    {
        String user = (o == null ? null : o.toString());
        if (user != null)
        {
            JSONObject item = new JSONObject();
            item.put(user, subscriptionService.follows(userId, user));
            result.add(item);
        }
    }

    return result;
}
 
Example 7
Project: talchain   File: GitHubTransactionTest.java   View source code 6 votes vote down vote up
@Test
public void testEIP155TransactionTestFromGitHub() throws ParseException, IOException {
    Set<String> excluded = new HashSet<>();
    SystemProperties.getDefault().setBlockchainConfig(new BaseNetConfig() {{
        add(0, new FrontierConfig());
        add(1_150_000, new HomesteadConfig());
        add(2_457_000, new Eip150HFConfig(new DaoHFConfig()));
        add(2_675_000, new Eip160HFConfig(new DaoHFConfig()){
            @Override
            public Integer getChainId() {
                return null;
            }
        });
    }});
    String json = JSONReader.loadJSONFromCommit("TransactionTests/EIP155/ttTransactionTest.json", shacommit);
    GitHubJSONTestSuite.runGitHubJsonTransactionTest(json, excluded);
}
 
Example 8
Project: Parabot-317-API-Minified-Dreamscape   File: Items.java   View source code 6 votes vote down vote up
/**
 * Returns an int array based on the string it contains. getIdsContain(dragon) will return an int array with all items containingdragon
 *
 * @param name
 *
 * @return
 */
public static int[] getIdsContain(String name) {
    try {
        String content = WebUtil.getContents(Configuration.ITEM_API + "contains/" + name);
        if (content.length() > 0) {
            JSONObject jsonObject = (JSONObject) jsonParser.parse(content);
            JSONArray  array      = (JSONArray) jsonObject.get("result");
            if (array.size() > 0) {
                int[] ids = new int[array.size()];
                for (int i = 0; i < array.size(); i++) {
                    ids[i] = Integer.parseInt((String) array.get(i));
                }
                return ids;
            }
        }
    } catch (MalformedURLException | ParseException e) {
        e.printStackTrace();
    }

    return new int[0];
}
 
Example 9
Project: rskj   File: GitHubStateTest.java   View source code 6 votes vote down vote up
@Test // testing full suite
public void testRandomStateGitHub() throws ParseException, IOException {

    String sha = "99db6f4f5fea3aa5cfbe8436feba8e213d06d1e8";
    List<String> fileNames = getFileNamesForTreeSha(sha);
    List<String> includedFiles =
            Arrays.asList(
                    "st201504081841JAVA.json",
                    "st201504081842JAVA.json",
                    "st201504081843JAVA.json"
            );

    for (String fileName : fileNames) {
        if (includedFiles.contains(fileName)) {
          System.out.println("Running: " + fileName);
          String json = JSONReader.loadJSON("StateTests//RandomTests/" + fileName);
          GitHubJSONTestSuite.runStateTest(json);
        }
    }

}
 
Example 10
Project: talchain   File: GitHubStateTest.java   View source code 6 votes vote down vote up
@Test
public void stWalletTest() throws ParseException, IOException {
    Set<String> excluded = new HashSet<>();

    String json = JSONReader.loadJSONFromCommit("StateTests/stWalletTest.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);

    json = JSONReader.loadJSONFromCommit("StateTests/Homestead/stWalletTest.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);

    json = JSONReader.loadJSONFromCommit("StateTests/EIP150/Homestead/stWalletTest.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);

    json = JSONReader.loadJSONFromCommit("StateTests/EIP158/Homestead/stWalletTest.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
}
 
Example 11
Project: aws-lambda-proxy-java   File: LambdaProxyHandlerTest.java   View source code 6 votes vote down vote up
@Test
public void shouldReturnServerErrorAndReasonWhenMisconfigured() throws ParseException {
    ApiGatewayProxyRequest request = new ApiGatewayProxyRequestBuilder()
            .withHttpMethod(METHOD)
            .build();
    LambdaProxyHandler<Configuration> handlerWithFailingConguration = new TestLambdaProxyHandlerWithFailingConguration();
    handlerWithFailingConguration.registerMethodHandler(METHOD, c -> methodHandler);

    ApiGatewayProxyResponse actual = handlerWithFailingConguration.handleRequest(request, context);

    assertThat(actual).isNotNull();
    assertThat(actual.getStatusCode()).isEqualTo(INTERNAL_SERVER_ERROR.getStatusCode());
    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = (JSONObject) jsonParser.parse(actual.getBody());
    assertThat(jsonObject.keySet()).contains("message", "cause");
    assertThat((String) jsonObject.get("message")).contains("This service is mis-configured. Please contact your system administrator.");
    assertThat((String) jsonObject.get("cause")).contains("NullPointerException");
}
 
Example 12
Project: rskj   File: GitHubVMTest.java   View source code 6 votes vote down vote up
@Test // testing full suite
public void testRandomVMGitHub() throws ParseException {

    String shacommit = "c5eafb85390eee59b838a93ae31bc16a5fd4f7b1";
    List<String> fileNames = getFileNamesForTreeSha(shacommit);
    List<String> excludedFiles =
            Collections.singletonList(
                    ""
            );

    for (String fileName : fileNames) {

        if (excludedFiles.contains(fileName)) continue;
        System.out.println("Running: " + fileName);
        String json = JSONReader.loadJSON("VMTests//RandomTests/" + fileName);
        GitHubJSONTestSuite.runGitHubJsonVMTest(json);
    }

}
 
Example 13
Project: KMUC   File: Carte.java   View source code 6 votes vote down vote up
/**
 * 네트워크 연결을 통한 모든 메뉴 JSON 파싱
 * @param reqAddress 모든 파라미터가 포함된 리퀘스트 주소
 * @return 모든 메뉴가 담긴 JSONObject
 * @throws IOException
 * @throws ParseException
 */
private JSONObject getAllMenuJson(String reqAddress) throws IOException, ParseException {
	HttpURLConnection conn = (HttpURLConnection)new URL(reqAddress).openConnection();
	conn.setRequestMethod("GET");
	conn.setRequestProperty("User-Agent", "Mozilla/5.0");
	conn.setConnectTimeout(5000);
	
	BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
	String line;
	StringBuilder sb = new StringBuilder();
	
	while((line = br.readLine()) != null){
		sb.append(line);
	}
	br.close();
	
	
	JSONParser parser = new JSONParser();
	JSONObject allMenu = (JSONObject)parser.parse(replace(sb.toString()));

	return allMenu;
}
 
Example 14
Project: rskj   File: GitHubBlockTest.java   View source code 5 votes vote down vote up
private void runHomestead(String name) throws IOException, ParseException {
    String json = JSONReader.loadJSONFromCommit("BlockchainTests/Homestead/" + name + ".json", shacommit);
    ConfigHelper.CONFIG.setBlockchainConfig(new GenesisConfig());
    try {
        GitHubJSONTestSuite.runGitHubJsonBlockTest(json, Collections.EMPTY_SET);
    } finally {
        ConfigHelper.CONFIG.setBlockchainConfig(MainNetConfig.INSTANCE);
    }
}
 
Example 15
Project: JHearthstone   File: Spell.java   View source code 5 votes vote down vote up
public JSONObject getEffect() {
    try {
        return new org.json.JSONObject(reader.getEffect(name).toJSONString());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return new org.json.JSONObject();
}
 
Example 16
Project: raven   File: MessageTool.java   View source code 5 votes vote down vote up
protected Result sendMessage(Constants.RequestPath requestPath, StringBuilder body, int retries) throws IOException, ParseException {
    int attempt = 0;
    Result result = null;
    int backoff = 1000;
    boolean tryAgain = false;

    do {
        ++attempt;
        if(logger.isLoggable(Level.FINE)) {
            logger.fine("Attempt #" + attempt + " to send " + body + " to url " + requestPath.getPath());
        }

        String bodyStr = body.toString();
        if(bodyStr.charAt(0) == 38) {
            bodyStr = body.toString().substring(1);
        }

        result = this.sendMessage(requestPath, bodyStr);
        tryAgain = result == null && attempt <= retries;
        if(tryAgain) {
            int sleepTime = backoff / 2 + this.random.nextInt(backoff);
            this.sleep((long)sleepTime);
            if(2 * backoff < 1024000) {
                backoff *= 2;
            }
        }
    } while(tryAgain);

    if(result == null) {
        throw this.exception(attempt);
    } else {
        return result;
    }
}
 
Example 17
Project: talchain   File: GitHubStateTest.java   View source code 5 votes vote down vote up
@Test
public void stRecursiveCreate() throws ParseException, IOException {
    Set<String> excluded = new HashSet<>();
    String json = JSONReader.loadJSONFromCommit("StateTests/stRecursiveCreate.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
    json = JSONReader.loadJSONFromCommit("StateTests/Homestead/stRecursiveCreate.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
    json = JSONReader.loadJSONFromCommit("StateTests/EIP150/Homestead/stRecursiveCreate.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
    json = JSONReader.loadJSONFromCommit("StateTests/EIP158/Homestead/stRecursiveCreate.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
}
 
Example 18
Project: rskj   File: GitHubStateTest.java   View source code 5 votes vote down vote up
@Test
public void stInitCodeTest() throws ParseException, IOException {
    Set<String> excluded = new HashSet<>();
    String json = JSONReader.loadJSONFromCommit("StateTests/stInitCodeTest.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);

}
 
Example 19
Project: JHearthstone   File: JSonReader.java   View source code 5 votes vote down vote up
public long getHealth(String n, String t) throws org.json.simple.parser.ParseException{
	long[] info = findCard(n, t);
	if(info[0] != 2){
		return info[3];
	}
	return -1;
}
 
Example 20
Project: rskj   File: GitHubStateTest.java   View source code 5 votes vote down vote up
@Test
public void stMemoryTest() throws ParseException, IOException {
    Set<String> excluded = new HashSet<>();

    String json = JSONReader.loadJSONFromCommit("StateTests/stMemoryTest.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);

}
 
Example 21
Project: JHearthstone   File: Test.java   View source code 5 votes vote down vote up
public static void main(String args[]) throws ParseException{
	ArrayList<String> hand = new ArrayList<>();
	hand.add("Northshire Cleric");
	hand.add("Claw");
	hand.add("Fiery War Axe");
	hand.add("Moonfire");
	for (int i = 0; i < 10; i++) {
		int random = (int) (Math.random() * hand.size());
		System.out.println(hand.get(random));
	}
}
 
Example 22
Project: bibliome-java-utils   File: ArabidoDiff2013.java   View source code 5 votes vote down vote up
public static void main(String[] args) throws ClassNotFoundException, SQLException, ParseException, IOException {
	switch (args[0]) {
		case "diff":
			doDiff(Integer.parseInt(args[1]), args[2], args[3], args[4], args[5]);
			break;
		case "docs":
			queryDocs(Arrays.asList(args).subList(1, args.length));
			break;
		default:
			throw new RuntimeException();
	}
}
 
Example 23
Project: otus_java_2017_04   File: SocketClientChannel.java   View source code 5 votes vote down vote up
private Msg getMsgFromJSON(String json) throws ParseException, ClassNotFoundException {
    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = (JSONObject) jsonParser.parse(json);
    String className = (String) jsonObject.get(Msg.CLASS_NAME_VARIABLE);
    Class<?> msgClass = Class.forName(className);
    return (Msg) new Gson().fromJson(json, msgClass);
}
 
Example 24
Project: open-weather-retriever-z   File: OpenWeatherRetrieverZ.java   View source code 5 votes vote down vote up
@Override
protected Void doInBackground(Void... objects) {
    try {
        this.weatherInfo = processWeatherInfo(this.url);
    } catch (IOException|ParseException e) {
        e.printStackTrace();
        callback.onFailure(e.toString());
    }
    return null;
}
 
Example 25
Project: open-weather-retriever-z   File: OpenWeatherRetrieverZ.java   View source code 5 votes vote down vote up
@Override
protected Void doInBackground(Object... objects) {
    try {
        dailyForecastInfoList = processDailyForecastInfo(url);
    } catch (IOException|ParseException e) {
        e.printStackTrace();
        callback.onFailure(e.toString());
    }
    return null;
}
 
Example 26
Project: MixPush   File: MiPushServerManager.java   View source code 5 votes vote down vote up
@Override
public void sendNotifyToAlias(List<String> alias, String title, String description, String messagePayload) throws IOException, ParseException {
    Constants.useOfficial();
    Sender sender = new Sender(appSecretKey);
    Message message = getNotifyMessage(title, description, messagePayload);

    for (String item : alias) {
        Result result = sender.sendToAlias(message, item, 10);
        System.out.println(item + ":" + result.toString());
    }
}
 
Example 27
Project: rskj   File: GitHubJSONTestSuite.java   View source code 5 votes vote down vote up
public static void runGitHubJsonSingleBlockTest(String json, String testName) throws ParseException, IOException {

        BlockTestSuite testSuite = new BlockTestSuite(json);
        Set<String> testCollection = testSuite.getTestCases().keySet();

        for (String testCase : testCollection) {
            if (testCase.equals(testName))
                logger.info(" => " + testCase);
            else
                logger.info("    " + testCase);
        }

        runSingleBlockTest(testSuite, testName);
    }
 
Example 28
Project: talchain   File: GitHubStateTest.java   View source code 5 votes vote down vote up
@Test
public void stPreCompiledContracts() throws ParseException, IOException {
    Set<String> excluded = new HashSet<>();

    String json = JSONReader.loadJSONFromCommit("StateTests/stPreCompiledContracts.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
    json = JSONReader.loadJSONFromCommit("StateTests/Homestead/stPreCompiledContracts.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
    json = JSONReader.loadJSONFromCommit("StateTests/EIP150/Homestead/stPreCompiledContracts.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
    json = JSONReader.loadJSONFromCommit("StateTests/EIP158/Homestead/stPreCompiledContracts.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
}
 
Example 29
Project: raven   File: Sender.java   View source code 5 votes vote down vote up
public Result sendToUserAccount(Message message, List<String> userAccounts, int retries) throws IOException, ParseException {
    int attempt = 0;
    Result result = null;
    int backoff = 1000;

    boolean tryAgain;
    do {
        ++attempt;
        if(logger.isLoggable(Level.FINE)) {
            logger.fine("Attempt #" + attempt + " to send message " + message + " to user account " + userAccounts);
        }

        result = this.sendToUserAccountNoRetry(message, userAccounts);
        tryAgain = result == null && attempt <= retries;
        if(tryAgain) {
            int sleepTime = backoff / 2 + this.random.nextInt(backoff);
            this.sleep((long)sleepTime);
            if(2 * backoff < 1024000) {
                backoff *= 2;
            }
        }
    } while(tryAgain);

    if(result == null) {
        throw this.exception(attempt);
    } else {
        return result;
    }
}
 
Example 30
Project: incubator-netbeans   File: DOMTest.java   View source code 5 votes vote down vote up
/**
 * Test of {@code handleCharacterDataModified} method.
 */
@Test
public void testHandleCharacterDataModified() throws ParseException {
    TransportImplementation transport = new DummyTransportImplementation();
    DOM dom = new DOM(new TransportHelper(transport), null);
    final Node root = dom.getDocument();
    final String DATA = "myData"; // NOI18N
    final int[] eventsFired = new int[1];
    DOM.Listener listener = new DOMAdapter() {
        @Override
        public void characterDataModified(Node node) {
            eventsFired[0]++;
            assertEquals(root, node);
            String value = root.getNodeValue();
            assertEquals(DATA, value);
        }
    };
    dom.addListener(listener);
    JSONParser parser = new JSONParser();

    // Modification of a known node
    Object json = parser.parse("{\"nodeId\":" + ROOT_NODE_ID + ",\"characterData\":\"" + DATA + "\"}"); // NOI18N
    dom.handleCharacterDataModified((JSONObject)json);
    assertEquals(1, eventsFired[0]);

    // Modification of an unknown node
    json = parser.parse("{\"nodeId\":" + (ROOT_NODE_ID+1) + ",\"characterData\":\"someData\"}"); // NOI18N
    dom.handleCharacterDataModified((JSONObject)json);
    assertEquals(1, eventsFired[0]);
}
 
Example 31
Project: talchain   File: GitHubStateTest.java   View source code 5 votes vote down vote up
@Test
public void stNonZeroCallsTest() throws ParseException, IOException {
    Set<String> excluded = new HashSet<>();

    String json = JSONReader.loadJSONFromCommit("StateTests/EIP158/stNonZeroCallsTest.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
}
 
Example 32
Project: talchain   File: GitHubStateTest.java   View source code 5 votes vote down vote up
@Test
public void stLogTests() throws ParseException, IOException {
    Set<String> excluded = new HashSet<>();
    String json = JSONReader.loadJSONFromCommit("StateTests/stLogTests.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
    json = JSONReader.loadJSONFromCommit("StateTests/Homestead/stLogTests.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
    json = JSONReader.loadJSONFromCommit("StateTests/EIP150/Homestead/stLogTests.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
    json = JSONReader.loadJSONFromCommit("StateTests/EIP158/Homestead/stLogTests.json", shacommit);
    GitHubJSONTestSuite.runStateTest(json, excluded);
}
 
Example 33
Project: incubator-netbeans   File: DOMTest.java   View source code 5 votes vote down vote up
/**
 * Test of {@code handleChildNodeInserted} method.
 */
@Test
public void testHandleChildNodeInserted() throws ParseException {
    TransportImplementation transport = new DummyTransportImplementation();
    DOM dom = new DOM(new TransportHelper(transport), null);
    final Node root = dom.getDocument();
    final int CHILD_ID = 2;
    final String CHILD_NAME = "DIV"; // NOI18N
    final int[] eventsFired = new int[1];
    DOM.Listener listener = new DOMAdapter() {
        @Override
        public void childNodeInserted(Node parent, Node child) {
            eventsFired[0]++;
            assertEquals(root, parent);
            List<Node> children = parent.getChildren();
            assertNotNull(children);
            assertEquals(1, children.size());
            assertEquals(child, children.get(0));
            assertEquals(CHILD_ID, child.getNodeId());
            assertEquals(CHILD_NAME, child.getNodeName());
        }
    };
    dom.addListener(listener);
    JSONParser parser = new JSONParser();

    // Modification of a known node
    Object json = parser.parse("{\"node\":{\"childNodeCount\":0,\"localName\":\"div\",\"nodeId\":" + // NOI18N
            CHILD_ID + ",\"nodeValue\":\"\",\"nodeName\":\"" + // NOI18N
            CHILD_NAME + "\",\"attributes\":[],\"nodeType\":1},\"parentNodeId\":" + // NOI18N
            ROOT_NODE_ID + ",\"previousNodeId\":0}"); // NOI18N
    assertNull(root.getChildren());
    dom.handleChildNodeInserted((JSONObject)json);
    assertEquals(1, eventsFired[0]);

    // Modification of an unknown node
    json = parser.parse("{\"node\":{\"childNodeCount\":0,\"localName\":\"div\",\"nodeId\":5,\"nodeValue\":\"\",\"nodeName\":\"DIV\",\"attributes\":[],\"nodeType\":1},\"parentNodeId\":5,\"previousNodeId\":0}"); // NOI18N
    dom.handleChildNodeInserted((JSONObject)json);
    assertEquals(1, eventsFired[0]);
}
 
Example 34
Project: incubator-netbeans   File: WebKitDebuggingTransport.java   View source code 5 votes vote down vote up
@Override
public Void call(final String p) {
    RP.post(new Runnable() {
        @Override
        public void run() {
            try {
                JSONObject json = (JSONObject)JSONValue.parseWithException(p);
                responseCallback.handleResponse(new Response(json));
            } catch (ParseException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    });
    return null;
}
 
Example 35
Project: rskj   File: LocalStateTest.java   View source code 5 votes vote down vote up
@Test
public void stTransitionTest() throws ParseException, IOException {
    Set<String> excluded = new HashSet<>();

    String json = getJSON("stTransitionTest");
    GitHubJSONTestSuite.runStateTest(json, excluded);
}
 
Example 36
Project: personium-core   File: UserDataWithNPDeclaredDoublePropertyTest.java   View source code 5 votes vote down vote up
/**
 * ZERO_ONE対ZERO_ONEのUserDataをNavigationProperty経由で取得して対象データが取得できること.
 * @throws ParseException パース例外
 */
@Test
public final void ZERO_ONE対ZERO_ONEのUserDataをNavigationProperty経由で取得して対象データが取得できること() throws ParseException {
    try {
        String sourceMultiplicity = "0..1";
        String targetMultiplicity = "0..1";
        checkSchemaTypeDouble(sourceMultiplicity, targetMultiplicity);
    } finally {
        CellUtils.bulkDeletion(BEARER_MASTER_TOKEN, CELL_NAME);
    }
}
 
Example 37
Project: keywordEntityApiRankService   File: AlchemyEntityAPI.java   View source code 5 votes vote down vote up
/**
 * Implemented receiveGET from Interface interfaceAPI (see for more details)
 *
 * @throws IOException
 *             IO Error
 * @throws ParseException
 *             Parse Error
 */
@Override
public void receiveGET() throws IOException, ParseException {
	JSONArray JSONArray = readResponseJSON(API_IDENTIFIER, EntityUtils.toString(httpEntity, "UTF-8"), "entities");

	if (JSONArray != null) {
		for (Object aJSONArray : JSONArray) {

			JSONObject object = (JSONObject) aJSONArray;
			ResponseEntry entity = new ResponseEntry();

			String s = (String) object.get("text");
			s = addEntity(s);

			// Add Entity only if it is new and has not been added before
			if (s != null) {
				entity.setEntry(s);
				entity.setConfidence(convertRelevance((String) object.get("relevance")));
				foundEntryList.add(entity);
			}
		}

		// Sort the Array List Entities from A to Z
		Collections.sort(foundEntryList, new SortResponseEntity());
		int i = 1;
		for (ResponseEntry e : foundEntryList) {
			LOG.debug("Entity " + i + " is " + e.getEntry() + "(" + e.getConfidence() + ")");
			i++;
		}
	}
}
 
Example 38
Project: keywordEntityApiRankService   File: MeaningCloudAPI.java   View source code 5 votes vote down vote up
/**
 * Implemented receiveGET from Interface interfaceAPI (see for more details)
 *
 * @throws IOException
 *             IO Error
 * @throws ParseException
 *             Parse Error
 */
public void receiveGET() throws IOException, ParseException {
	JSONArray JSONArray = readResponseJSON(API_IDENTIFIER, EntityUtils.toString(httpEntity, "UTF-8"), "entity_list");

	if (JSONArray != null) {
		for (Object aJSONArray : JSONArray) {

			JSONObject object = (JSONObject) aJSONArray;
			ResponseEntry entity = new ResponseEntry();

			String s = (String) object.get("form");
			s = addEntity(s);

			// Add Entity only if it is new and has not been added before
			if (s != null) {
				entity.setEntry(s);
				entity.setConfidence(convertRelevance((String) object.get("relevance")));
				foundEntryList.add(entity);
			}
		}

		// Sort the Array List Entities from A to Z
		Collections.sort(foundEntryList, new SortResponseEntity());

		int i = 1;
		for (ResponseEntry e : foundEntryList) {
			LOG.debug("Entity " + i + " is " + e.getEntry() + "(" + e.getConfidence() + ")");
			i++;
		}
	}
}
 
Example 39
Project: AppCoins-ethereumj   File: GitHubTransactionTest.java   View source code 5 votes vote down vote up
@Test
public void ttWrongRLPFrontier() throws IOException, ParseException {
    suite.run("ttWrongRLPFrontier", new HashSet<>(Arrays.asList(
            "RLPArrayLengthWithFirstZeros",    // TODO fix those tests, it just fails
            "RLPIncorrectByteEncoding00",
            "RLPIncorrectByteEncoding01",
            "RLPIncorrectByteEncoding127",
            "RLPListLengthWithFirstZeros"
    )));
}
 
Example 40
Project: java-velocypack   File: VPackParser.java   View source code 5 votes vote down vote up
private void add(final Boolean value) throws ParseException {
	try {
		builder.add(attribute, value);
		attribute = null;
	} catch (final VPackBuilderException e) {
		throw new ParseException(ParseException.ERROR_UNEXPECTED_EXCEPTION);
	}
}