Skip to content

Commit

Permalink
Added a few tests for the xPath lookup class
Browse files Browse the repository at this point in the history
  • Loading branch information
frossm committed Jul 18, 2023
1 parent 8bc3b7f commit 324aebf
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/main/java/org/fross/quoter/XPathLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
*
* Quoter is a command line program that display stock quotes and index data.
*
* * Copyright (c) 2019-2022 Michael Fross
* Copyright (c) 2019-2022 Michael Fross
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Expand All @@ -39,7 +39,7 @@ public class XPathLookup {
*/
public XPathLookup() {
// ---------------------------------------------------------------------------------
// Symbols with market CLOSED
// xPaths: Symbols with market CLOSED
// ---------------------------------------------------------------------------------
symbolClosed.put("latestPrice", "/html/body/div[3]/div[2]/div[3]/div/div[4]/table/tbody/tr/td[1]");
symbolClosed.put("change", "/html/body/div[3]/div[2]/div[3]/div/div[4]/table/tbody/tr/td[2]");
Expand All @@ -52,7 +52,7 @@ public XPathLookup() {
symbolClosed.put("fullname", "/html/body/div[3]/div[2]/div[2]/div/div[2]/h1");

// ---------------------------------------------------------------------------------
// Symbols with market OPEN
// xPaths: Symbols with market OPEN
// ---------------------------------------------------------------------------------
symbolOpen.put("latestPrice", "/html/body/div[3]/div[2]/div[3]/div/div[2]/h2/bg-quote");
symbolOpen.put("change", "/html/body/div[3]/div[2]/div[3]/div/div[2]/bg-quote/span[1]/bg-quote");
Expand All @@ -65,7 +65,7 @@ public XPathLookup() {
symbolOpen.put("fullname", "/html/body/div[3]/div[2]/div[2]/div/div[2]/h1");

// ---------------------------------------------------------------------------------
// Indexes with market CLOSED
// xPaths: Indexes with market CLOSED
// ---------------------------------------------------------------------------------
indexClosed.put("latestPrice", "/html/body/div[3]/div[2]/div[3]/div/div[2]/h2/span");
indexClosed.put("change", "/html/body/div[3]/div[2]/div[3]/div/div[2]/bg-quote/span[1]");
Expand All @@ -76,7 +76,7 @@ public XPathLookup() {
indexClosed.put("timeStamp", "/html/body/div[3]/div[2]/div[3]/div/div[1]/span/bg-quote");

// ---------------------------------------------------------------------------------
// Indexes with market OPEN
// xPaths: Indexes with market OPEN
// ---------------------------------------------------------------------------------
indexOpen.put("latestPrice", "/html/body/div[3]/div[2]/div[3]/div/div[2]/h2/bg-quote");
indexOpen.put("change", "/html/body/div[3]/div[2]/div[3]/div/div[2]/bg-quote/span[1]/bg-quote");
Expand All @@ -91,7 +91,7 @@ public XPathLookup() {
}

/**
* lookupSymbolOpen(): Returns the xPath string as maped to the provided key
* lookupSymbolOpen(): Returns the xPath string as mapped to the provided key
*
* @param key
* @return
Expand All @@ -101,7 +101,7 @@ public String lookupSymbolOpen(String key) {
}

/**
* lookupSymbolClosed(): Returns the xPath string as maped to the provided key
* lookupSymbolClosed(): Returns the xPath string as mapped to the provided key
*
* @param key
* @return
Expand All @@ -111,7 +111,7 @@ public String lookupSymbolClosed(String key) {
}

/**
* lookupIndexOpen(): Returns the xPath string as maped to the provided key
* lookupIndexOpen(): Returns the xPath string as mapped to the provided key
*
* @param key
* @return
Expand All @@ -121,7 +121,7 @@ public String lookupIndexOpen(String key) {
}

/**
* lookupIndexClosed(): Returns the xPath string as maped to the provided key
* lookupIndexClosed(): Returns the xPath string as mapped to the provided key
*
* @param key
* @return
Expand Down
103 changes: 103 additions & 0 deletions src/test/java/org/fross/quoter/XPathLookupTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**************************************************************************************************************
* Quoter.jar
*
* Quoter is a command line program that display stock quotes and index data.
*
* Copyright (c) 2019-2022 Michael Fross
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
***************************************************************************************************************/
package org.fross.quoter;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.junit.jupiter.api.Test;

class XPathLookupTest {

// Simple test - make sure each of the xPath hash maps have the right number of fields
@Test
void fieldTest() {
XPathLookup xPathLookup = new XPathLookup();

assertEquals(9, xPathLookup.symbolClosed.size());
assertEquals(9, xPathLookup.symbolOpen.size());
assertEquals(7, xPathLookup.indexClosed.size());
assertEquals(8, xPathLookup.indexOpen.size());
}

// Ensure that some text exists within each lookup value
@Test
void contentTest() {
XPathLookup xPathLookup = new XPathLookup();

// lookupSymbolClosed
for (String value : xPathLookup.symbolClosed.keySet())
assertFalse(xPathLookup.symbolClosed.get(value).isEmpty());

// lookupSymbolOpen
for (String value : xPathLookup.symbolOpen.keySet())
assertFalse(xPathLookup.symbolOpen.get(value).isEmpty());

// lookupIndexClosed
for (String value : xPathLookup.indexClosed.keySet())
assertFalse(xPathLookup.indexClosed.get(value).isEmpty());

// lookupIndexOpen
for (String value : xPathLookup.indexOpen.keySet())
assertFalse(xPathLookup.indexOpen.get(value).isEmpty());

}

// Do a few lookups and just make sure we get non-null back
@Test
void lookupTests() {
XPathLookup xPathLookup = new XPathLookup();

// lookupSymbolClosed
assertNotNull(xPathLookup.lookupSymbolClosed("latestPrice"));
assertNotNull(xPathLookup.lookupSymbolClosed("fullname"));
assertNull(xPathLookup.lookupSymbolClosed("xxx"));
assertNull(xPathLookup.lookupSymbolClosed("yyy"));

// lookupSymbolOpen
assertNotNull(xPathLookup.lookupSymbolOpen("change"));
assertNotNull(xPathLookup.lookupSymbolOpen("52weekRange"));
assertNull(xPathLookup.lookupSymbolOpen("xxx"));
assertNull(xPathLookup.lookupSymbolOpen("yyy"));

// lookupIndexClosed
assertNotNull(xPathLookup.lookupIndexClosed("oneYearChangePercent"));
assertNotNull(xPathLookup.lookupIndexClosed("timeStamp"));
assertNull(xPathLookup.lookupIndexClosed("xxx"));
assertNull(xPathLookup.lookupIndexClosed("yyy"));

// lookupIndexOpen
assertNotNull(xPathLookup.lookupIndexOpen("marketStatus"));
assertNotNull(xPathLookup.lookupIndexOpen("52weekRange"));
assertNull(xPathLookup.lookupIndexOpen("xxx"));
assertNull(xPathLookup.lookupIndexOpen("yyy"));

}

}

0 comments on commit 324aebf

Please sign in to comment.