Skip to content

Commit

Permalink
Initial Commit with tons of cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianKirmaier committed May 22, 2024
1 parent 1b695cf commit b0ec038
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 196 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ JPRO_PLATFORM_VERSION = 0.3.2-SNAPSHOT

JPRO_VERSION = 2024.2.0
JAVAFX_VERSION = 17.0.11
SIMPLEFX_VERSION = 3.2.33
SIMPLEFX_VERSION = 3.2.34
JMEMORYBUDDY_VERSION = 0.5.3
JNODES_VERSION = 0.8.1
SCENIC_VIEW_VERSION = 11.0.3-SNAPSHOT-FORK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ class TestAppCrawler {

@Test
def testCrawlApp(): Unit = {
def app = new RouteNode(null) {
setRoute(Route.empty()
def route = Route.empty()
.and(Route.get("/", r => Response.view(new Page1)))
.and(Route.get("/page2", r => Response.view(new Page2))))
}
val result = AppCrawler.crawlApp("http://localhost", () => app)
.and(Route.get("/page2", r => Response.view(new Page2)))
val result = AppCrawler.crawlRoute("http://localhost", () => route)

assert(result.pages.contains("/"), result.pages)
assert(result.pages.contains("/page2"), result.pages)
Expand All @@ -48,17 +46,15 @@ class TestAppCrawler {

@Test
def testEmptyImage(): Unit = {
def app = new RouteNode(null) {
setRoute(Route.empty()
def route = Route.empty()
.and(Route.get("/", r => Response.view(new View {
override def title: String = ""

override def description: String = ""

override def content: all.Node = new ImageView(null: Image)
}))))
}
val result = AppCrawler.crawlApp("http://localhost", () => app)
})))
val result = AppCrawler.crawlRoute("http://localhost", () => route)
}

@Test
Expand Down Expand Up @@ -99,16 +95,19 @@ class TestAppCrawler {
}

@Test
def testImageInStyle (): Unit = inFX {
val view = new View {
def testImageInStyle (): Unit = {
def view = new View {
override def title: String = ""
override def description: String = ""
val content: Node = new Region() {
style = "-fx-background-image: url('/testfiles/test.jpg');"
}
}
val r = AppCrawler.crawlPage(view)
assert(r.pictures.nonEmpty)
val r = AppCrawler.crawlRoute("http://localhost", () =>
Route.empty().and(Route.get("/", r => Response.view(view)))
)
assert(r.pages.length == 1)
assert(r.reports.head.pictures.nonEmpty)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,48 @@ class TestMemoryTester {

@Test
def simpleTest(): Unit = {
def app = new RouteNode(null) {
setRoute(Route.empty()
def route = Route.empty()
.and(Route.get("/", r => Response.view(new Page1)))
.and(Route.get("/page2", r => Response.view(new Page2)))
.and(Route.get("/page4", r => Response.view(new Page2))))
}
val result = AppCrawler.crawlApp("http://localhost", () => app)
MemoryTester.testForLeaks(result, () => app)
.and(Route.get("/page4", r => Response.view(new Page2)))
val result = AppCrawler.crawlRoute("http://localhost", () => route)
MemoryTester.testForLeaks(result, () => route)
}

@Test
def simpleFailingTest(): Unit = {
val page2 = new Page2
def app = new RouteNode(null) {
setRoute(Route.empty()
def route = Route.empty()
.and(Route.get("/", r => Response.view(new Page1)))
.and(Route.get("/page2", r => Response.view(page2)))
.and(Route.get("/page4", r => Response.view(new Page2))))
}
val result = AppCrawler.crawlApp("http://localhost", () => app)
intercept[Throwable](MemoryTester.testForLeaks(result, () => app))
.and(Route.get("/page4", r => Response.view(new Page2)))
val result = AppCrawler.crawlRoute("http://localhost", () => route)
intercept[Throwable](MemoryTester.testForLeaks(result, () => route))
}

@Test
def simpleFailingTest2(): Unit = {
var node2 = new Label()

def app = new RouteNode(null) {
setRoute(Route.empty()
def route = Route.empty()
.and(Route.get("/", r => Response.view(new Page1)))
.and(Route.get("/page2", r => Response.node(node2)))
.and(Route.get("/page4", r => Response.view(new Page2))))
}
.and(Route.get("/page4", r => Response.view(new Page2)))

val result = AppCrawler.crawlApp("http://localhost", () => app)
intercept[Throwable](MemoryTester.testForLeaks(result, () => app))
val result = AppCrawler.crawlRoute("http://localhost", () => route)
intercept[Throwable](MemoryTester.testForLeaks(result, () => route))
}

/*
@Test
def simpleFailingTest3(): Unit = {
val app = inFX(new RouteNode(null) {
setRoute(Route.empty()
val route = inFX(Route.empty()
.and(Route.get("/", r => Response.view(new Page1)))
.and(Route.get("/page2", r => Response.view(new Page2)))
.and(Route.get("/page4", r => Response.view(new Page2))))
})
val result = AppCrawler.crawlApp("http://localhost", () => app)
intercept[Throwable](MemoryTester.testForLeaks(result, () => app)) // fails because the webapp is not collectable
.and(Route.get("/page4", r => Response.view(new Page2)))
)
val result = AppCrawler.crawlApp("http://localhost", () => route)
intercept[Throwable](MemoryTester.testForLeaks(result, () => route)) // fails because the webapp is not collectable
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,27 @@ import simplefx.experimental._
class TestSitemapGenerator {
@Test
def test(): Unit = {
def app = new RouteNode(null) {
setRoute(Route.empty()
def route = Route.empty()
.and(get("/", r => Response.view(new Page1)))
.and(get("/page2", r => Response.view(new Page2)))
.and(get("/page4", r => Response.view(new Page2)))
.and(r => Response.view(new Page1)))
}
val result = AppCrawler.crawlApp("http://localhost", () => app)
.and(r => Response.view(new Page1))
val result = AppCrawler.crawlRoute("http://localhost", () => route)
val sm = SitemapGenerator.createSitemap("http://localhost", result)
println("Crawl Report: " + result)
println("SiteMap: " + sm)
assert(sm.contains("<loc>http://localhost/page4</loc>"))
assert(!sm.contains("<loc>http://external/link</loc>"))

assert(sm.contains("<loc>http://localhost/page4</loc>"), "sitemap did not contain page4")
assert(!sm.contains("<loc>http://external/link</loc>"), "sitemap contained external link")
assert(!sm.contains("mailto"))
}

@Test
def testMailToRedirect(): Unit = {
def app = new RouteNode(null) {
setRoute(Route.empty()
.and(get("/", r => Response.view(pageWithLink(List("/page2", "/page3", "mailto:something")))))
.and(get("/page2", r => Response.redirect("mailto:something-2"))))
}
val result = AppCrawler.crawlApp("http://localhost", () => app)
def route = Route.empty()
.and(get("/", r => Response.view(pageWithLink(List("/page2", "/page3", "mailto:something")))))
.and(get("/page2", r => Response.redirect("mailto:something-2")))
val result = AppCrawler.crawlRoute("http://localhost", () => route)
println("got result: " + result)
val sm = SitemapGenerator.createSitemap("http://localhost", result)
println("SiteMap2: " + sm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ object LinkUtil {
}

def getSessionManager(node: Node): SessionManager = {
SessionManagerContext.getContext(node)
val sm = SessionManagerContext.getContext(node)
assert(sm != null, "SessionManager was null")
sm
}

def setLink(node: Node, url: String): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,23 @@ object Request {
private lazy val logger: Logger = LoggerFactory.getLogger(getClass.getName)

private var wref_null = new WeakReference[Node](null)
def fromString(x: String): Request = {
if(!isValidLink(x)) {
logger.warn("Warning - Invalid Link: " + x)

def fromString(s: String, oldView: Node): Request = {
val oldViewW = new WeakReference(oldView)
Request.fromString(s).copy(oldContent = oldViewW, origOldContent = oldViewW)
}
def fromString(s: String): Request = {
if(!isValidLink(s)) {
logger.warn("Warning - Invalid Link: " + s)
}
val uri = new URI(x)
val uri = new URI(s)
val rawQuery = uri.getRawQuery
val query: Map[String,String] = if(rawQuery == null || rawQuery == "") Map() else rawQuery.split("&").map(x => {
val Array(a,b) = x.split("=")
a -> b
}).toMap
val path = uri.getPath
val res = Request(x, uri.getScheme, uri.getHost, uri.getPort, path,path,"/", query,wref_null,wref_null)
val res = Request(s, uri.getScheme, uri.getHost, uri.getPort, path,path,"/", query,wref_null,wref_null)
res
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,9 @@ class RouteNode(stage: Stage, route: Route) extends StackPane { THIS =>
lazy val webAPI: WebAPI = if(WebAPI.isBrowser) com.jpro.webapi.WebAPI.getWebAPI(stage) else null

var newRoute: Route = route
def getRoute: Route = newRoute
def getRoute(): Route = newRoute
def setRoute(x: Route): Unit = newRoute = x

def route(s: String, oldView: Node) = {
val oldViewW = new WeakReference(oldView)
newRoute(Request.fromString(s).copy(oldContent = oldViewW, origOldContent = oldViewW))
}
def route = {
(s: String) => newRoute(Request.fromString(s))
}


def start(sessionManager: SessionManager) = {
SessionManagerContext.setContext(this, sessionManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class View extends ResponseResult { THIS =>
* @param x path
* @return whether the view handles the url change
*/
def handleURL(x: String): Boolean = false
def handleRequest(x: Request): Boolean = false
def mapContent(f: Node => Node): View = new View {
override def title: String = THIS.title

Expand Down
Loading

0 comments on commit b0ec038

Please sign in to comment.