-
Notifications
You must be signed in to change notification settings - Fork 163
Improve installer form initialization and preview navigation #182
New issue
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
.../test/java/org/apache/roller/weblogger/business/startup/DatabaseInstallerUpgradeTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0. | ||
| */ | ||
| package org.apache.roller.weblogger.business.startup; | ||
|
|
||
| import java.sql.*; | ||
| import java.util.Properties; | ||
| import org.apache.roller.weblogger.business.DatabaseProvider; | ||
| import org.junit.jupiter.api.Test; | ||
| import static org.mockito.Mockito.*; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class DatabaseInstallerUpgradeTest { | ||
| @Test | ||
| void versionOnlyUpgradeReportsCompletion() throws Exception { | ||
| DatabaseProvider db = mock(DatabaseProvider.class); | ||
| DatabaseScriptProvider scripts = mock(DatabaseScriptProvider.class); | ||
| Connection con = mock(Connection.class); | ||
| Statement query = mock(Statement.class); | ||
| ResultSet rows = mock(ResultSet.class); | ||
| PreparedStatement update = mock(PreparedStatement.class); | ||
| when(db.getConnection()).thenReturn(con); | ||
| when(con.createStatement()).thenReturn(query); | ||
| when(query.executeQuery(anyString())).thenReturn(rows); | ||
| when(rows.next()).thenReturn(true); | ||
| when(rows.getString(1)).thenReturn("610"); | ||
| when(con.prepareStatement(anyString())).thenReturn(update); | ||
| DatabaseInstaller installer = new DatabaseInstaller(db, scripts); | ||
|
|
||
| // the version the installer writes is the one it reads from | ||
| // /roller-version.properties, so derive the expectation from the | ||
| // same source and parser instead of pinning a release constant | ||
| Properties props = new Properties(); | ||
| props.load(getClass().getResourceAsStream("/roller-version.properties")); | ||
| int expectedVersion = DatabaseInstaller.parseVersionString(props.getProperty("ro.version", "UNKNOWN")); | ||
|
|
||
| installer.upgradeDatabase(true); | ||
| verify(update).setString(1, String.valueOf(expectedVersion)); | ||
| verify(update).executeUpdate(); | ||
| verifyNoInteractions(scripts); | ||
| assertTrue(installer.getMessages().stream().anyMatch(m -> m.contains("No table changes were required."))); | ||
| assertTrue(installer.getMessages().stream().anyMatch(m -> m.contains("Database version updated to " + expectedVersion + "."))); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/InstallTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0. | ||
| */ | ||
| package org.apache.roller.weblogger.ui.struts2.core; | ||
|
|
||
| import org.apache.roller.weblogger.business.WebloggerFactory; | ||
| import org.apache.roller.weblogger.business.startup.*; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.MockedStatic; | ||
| import static org.mockito.Mockito.*; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class InstallTest { | ||
| @Test | ||
| void installerExposesItsTitleAndExceptionName() { | ||
| Install action = spy(new Install()); | ||
| doAnswer(i -> i.getArgument(0)).when(action).getText(anyString()); | ||
| assertEquals("", action.getRootCauseExceptionName()); | ||
| try (MockedStatic<WebloggerFactory> factory = mockStatic(WebloggerFactory.class); | ||
| MockedStatic<WebloggerStartup> startup = mockStatic(WebloggerStartup.class)) { | ||
| startup.when(WebloggerStartup::getDatabaseProviderException) | ||
| .thenReturn(new StartupException("Connection failed", new IllegalStateException("offline"))); | ||
| assertEquals("database_error", action.execute()); | ||
| assertEquals("installer.error.connection.pageTitle", action.getPageTitle()); | ||
| assertEquals("java.lang.IllegalStateException", action.getRootCauseExceptionName()); | ||
| } | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/EntryEditPreviewTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0. | ||
| */ | ||
| package org.apache.roller.weblogger.ui.struts2.editor; | ||
|
|
||
| import java.net.URI; | ||
| import org.apache.roller.weblogger.business.*; | ||
| import org.apache.roller.weblogger.config.WebloggerRuntimeConfig; | ||
| import org.apache.roller.weblogger.pojos.*; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.MockedStatic; | ||
| import static org.mockito.Mockito.*; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class EntryEditPreviewTest { | ||
| @Test | ||
| void previewUsesTheEditorsOrigin() { | ||
| Weblogger weblogger = mock(Weblogger.class); | ||
| when(weblogger.getUrlStrategy()).thenReturn(new MultiWeblogURLStrategy()); | ||
| try (MockedStatic<WebloggerFactory> factory = mockStatic(WebloggerFactory.class); | ||
| MockedStatic<WebloggerRuntimeConfig> config = mockStatic(WebloggerRuntimeConfig.class)) { | ||
| factory.when(WebloggerFactory::getWeblogger).thenReturn(weblogger); | ||
| config.when(WebloggerRuntimeConfig::getAbsoluteContextURL).thenReturn("http://other.example/roller"); | ||
| Weblog weblog = new Weblog(); | ||
| weblog.setHandle("mainpage"); | ||
| WeblogEntry entry = new WeblogEntry(); | ||
| entry.setAnchor("test entry"); | ||
| EntryEdit action = new EntryEdit(); | ||
| action.setActionWeblog(weblog); | ||
| action.setEntry(entry); | ||
| for (String context : new String[]{"", "/roller"}) { | ||
| config.when(WebloggerRuntimeConfig::getRelativeContextURL).thenReturn(context); | ||
| String preview = action.getPreviewURL(); | ||
| assertEquals(context + "/roller-ui/authoring/preview/mainpage/?previewEntry=test+entry", preview); | ||
| for (String scheme : new String[]{"http", "https"}) { | ||
| URI editor = URI.create(scheme + "://example.org:8443" + context + "/roller-ui/authoring/entryEdit.rol"); | ||
| URI target = editor.resolve(preview); | ||
| assertEquals(editor.getScheme(), target.getScheme()); | ||
| assertEquals(editor.getAuthority(), target.getAuthority()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
probably ok for now but this is also a bit brittle.
I think this pattern would be more future proof.
But this can be tweaked for the next release.
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.
gh didn't select the full span, the brittle part is L229
boolean schemaChangesRequired = dbversion < 610;.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.
Thanks — adopted your flag pattern in #184: a
schemaUpgradedflag set inside each upgrade block, so the "no table changes" message no longer depends on the hardcoded 610. It's behavior-preserving (at that pointdbversion < 610is true exactly when a block runs), and I added a test for the schema-change path. Folding it into 6.1.6.