Skip to content

Commit

Permalink
Merge branch 'work/using-react-with-bootstrap4'
Browse files Browse the repository at this point in the history
  • Loading branch information
steinarb committed Dec 14, 2024
2 parents 140595b + 687ba05 commit b331b92
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 50 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>no.priv.bang.pom</groupId>
<artifactId>bang-authservice-client-pom</artifactId>
<version>2.0.6</version>
<version>2.0.8</version>
</parent>
<groupId>no.priv.bang.ukelonn</groupId>
<artifactId>ukelonn</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import static no.priv.bang.ukelonn.UkelonnConstants.*;

class UkelonnServiceProviderTest {
private final static Locale NB_NO = Locale.forLanguageTag("nb-no");
private static final Locale NB_NO = Locale.forLanguageTag("nb-no");

@BeforeAll
static void setupForAllTests() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ private static DataSource createDataSource(String dbname) throws SQLException {
var derbyDataSourceFactory = new DerbyDataSourceFactory();
var properties = new Properties();
properties.setProperty(DataSourceFactory.JDBC_URL, "jdbc:derby:memory:" + dbname + ";create=true");
var datasource = derbyDataSourceFactory.createDataSource(properties);
return datasource;
return derbyDataSourceFactory.createDataSource(properties);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ public boolean rollbackMockData(DataSource datasource) {
try(var statement = connect.prepareStatement("delete from users")) {
statement.executeUpdate();
}
var liquibase = new Liquibase(dummyDataResourceName(), classLoaderResourceAccessor, databaseConnection);
liquibase.rollback(3, "");
try(var liquibase = new Liquibase(dummyDataResourceName(), classLoaderResourceAccessor, databaseConnection)) {
liquibase.rollback(3, "");
}
}
return true;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ void testPrepareDatabase() throws Exception {
try(var onAccount = statement.executeQuery()) {
assertNotNull(onAccount);
assertTrue(onAccount.next());
var account_id = onAccount.getInt("account_id");
var accountId = onAccount.getInt("account_id");
var username = onAccount.getString("username");
var balance = onAccount.getFloat("balance");
assertEquals(4, account_id);
assertEquals(4, accountId);
assertEquals("jad", username);
assertThat(balance).isPositive();
}
Expand Down Expand Up @@ -106,10 +106,10 @@ void testPrepareDatabaseWithConfiguredLanguage() throws SQLException, DatabaseEx
try(var onAccount = statement.executeQuery()) {
assertNotNull(onAccount);
assertTrue(onAccount.next());
var account_id = onAccount.getInt("account_id");
var accountId = onAccount.getInt("account_id");
var username = onAccount.getString("username");
var balance = onAccount.getFloat("balance");
assertEquals(4, account_id);
assertEquals(4, accountId);
assertEquals("jad", username);
assertThat(balance).isPositive();
}
Expand Down Expand Up @@ -147,10 +147,10 @@ void testPrepareDatabaseWithConfiguredLanguageNotFound() throws SQLException, Da
try(var onAccount = statement.executeQuery()) {
assertNotNull(onAccount);
assertTrue(onAccount.next());
var account_id = onAccount.getInt("account_id");
var accountId = onAccount.getInt("account_id");
var username = onAccount.getString("username");
var balance = onAccount.getFloat("balance");
assertEquals(4, account_id);
assertEquals(4, accountId);
assertEquals("jad", username);
assertThat(balance).isPositive();
}
Expand All @@ -172,7 +172,7 @@ void testPrepareDatabaseWithConfiguredLanguageNotFound() throws SQLException, Da
}

@Test
void testFailWhenPrepareDatabase() throws SQLException, DatabaseException {
void testFailWhenPrepareDatabase() throws SQLException {
var datasource = mock(DataSource.class);
var runner = new TestLiquibaseRunner();
var logservice = new MockLogService();
Expand Down Expand Up @@ -421,17 +421,15 @@ private CredentialsMatcher createSha256HashMatcher(int iterations) {
private SimpleAuthenticationInfo createAuthenticationInfo(String principal, String hashedPassword, String salt) {
var decodedPassword = Sha256Hash.fromBase64String(hashedPassword);
var decodedSalt = Util.bytes(Base64.getDecoder().decode(salt));
var authenticationInfo = new SimpleAuthenticationInfo(principal, decodedPassword, decodedSalt, "ukelonn");
return authenticationInfo;
return new SimpleAuthenticationInfo(principal, decodedPassword, decodedSalt, "ukelonn");
}

private int findTheNumberOfRowsInTable(DataSource datasource, String tableName) throws Exception {
var selectAllRowsStatement = String.format("select * from %s", tableName);
try(var connection = datasource.getConnection()) {
try(var selectAllRowsInTable = connection.prepareStatement(selectAllRowsStatement)) {
var userResults = selectAllRowsInTable.executeQuery();
var numberOfRows = countResults(userResults);
return numberOfRows;
return countResults(userResults);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
package no.priv.bang.ukelonn.db.liquibase;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import liquibase.exception.DatabaseException;
import liquibase.exception.LiquibaseException;
import no.priv.bang.authservice.db.liquibase.AuthserviceLiquibase;
import no.priv.bang.authservice.definitions.AuthserviceException;
Expand All @@ -44,7 +45,7 @@ public void updateSchema(DataSource datasource) throws LiquibaseException {
applyLiquibaseChangelist(connect, "ukelonn-db-changelog/db-changelog-1.0.1.xml");
} catch (LiquibaseException e) {
throw e;
} catch (Exception e1) {
} catch (SQLException e1) {
throw new UkelonnException(ERROR_CLOSING_RESOURCE_WHEN_UPDATING_UKELONN_SCHEMA, e1);
}

Expand All @@ -53,20 +54,20 @@ public void updateSchema(DataSource datasource) throws LiquibaseException {
authserviceLiquibase.createInitialSchema(connect);
} catch (LiquibaseException | AuthserviceException e) {
throw e;
} catch (Exception e1) {
} catch (SQLException e1) {
throw new UkelonnException(ERROR_CLOSING_RESOURCE_WHEN_UPDATING_UKELONN_SCHEMA, e1);
}

try (var connect = datasource.getConnection()) {
applyLiquibaseChangelist(connect, "ukelonn-db-changelog/db-changelog.xml");
} catch (LiquibaseException e) {
throw e;
} catch (Exception e1) {
} catch (SQLException e1) {
throw new UkelonnException(ERROR_CLOSING_RESOURCE_WHEN_UPDATING_UKELONN_SCHEMA, e1);
}
}

private void applyLiquibaseChangelist(Connection connect, String liquibaseChangeLogClassPathResource) throws Exception, DatabaseException {
private void applyLiquibaseChangelist(Connection connect, String liquibaseChangeLogClassPathResource) throws LiquibaseException {
applyLiquibaseChangelist(connect, liquibaseChangeLogClassPathResource, getClass().getClassLoader());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,19 @@ private void assertBonus(ResultSet results, boolean enabled, String title, Strin
assertEquals(endDate, new Date(results.getTimestamp("end_date").getTime()));
}

static private Connection createConnection() throws Exception {
private static Connection createConnection() throws Exception {
return dataSource.getConnection();
}

static private Connection createConnection(String dbname) throws Exception {
private static Connection createConnection(String dbname) throws Exception {
return createDataSource(dbname).getConnection();
}

private static DataSource createDataSource(String dbname) throws SQLException {
var derbyDataSourceFactory = new DerbyDataSourceFactory();
var properties = new Properties();
properties.setProperty(DataSourceFactory.JDBC_URL, "jdbc:derby:memory:" + dbname + ";create=true");
var datasource = derbyDataSourceFactory.createDataSource(properties);
return datasource;
return derbyDataSourceFactory.createDataSource(properties);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
public class UkelonnServiceIntegrationTest extends KarafTestSupport {

@Configuration
@Override
public Option[] config() {
final var ukelonnFeatureRepo = maven()
.groupId("no.priv.bang.ukelonn")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
*
*/
class UkelonnRestApiServletTest extends ServletTestBase {
private final static Locale NB_NO = Locale.forLanguageTag("nb-no");
private final static Locale EN_UK = Locale.forLanguageTag("en-uk");
private static final Locale NB_NO = Locale.forLanguageTag("nb-no");
private static final Locale EN_UK = Locale.forLanguageTag("en-uk");

UkelonnRestApiServletTest() {
super("/ukelonn", "/api");
Expand Down Expand Up @@ -389,19 +389,15 @@ void testLogoutNotLoggedIn() throws Exception {

var servlet = simulateDSComponentActivationAndWebWhiteboardConfiguration(ukelonn, logservice, useradmin);

// Log in non-admin user
loginUser(request, response, "jad", "1ad");
// Set up Shiro to be in a not logged-in state
var subject = createSubjectAndBindItToThread(request, response);
subject.logout();

// Do the logout
servlet.service(request, response);

// Check the response
assertEquals(200, response.getStatus());
assertEquals("application/json", response.getContentType());

var result = ServletTestBase.mapper.readValue(response.getOutputStreamContent(), LoginResult.class);
assertThat(result.roles()).isEmpty();
assertEquals("", result.errorMessage());
assertEquals(401, response.getStatus());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void testUpdateJob() {
var originalTransactionAmount = job.transactionAmount();

// Find a different job type that has a different amount
var newJobType = findJobTypeWithDifferentIdAndAmount(ukelonn, originalTransactionTypeId, originalTransactionAmount);
var newJobType = findJobTypeWithDifferentIdAndAmount(originalTransactionTypeId, originalTransactionAmount);

// Create a new job object with a different jobtype and the same id
var now = new Date();
Expand Down Expand Up @@ -324,8 +324,8 @@ void testUpdateJobGetSQLException() throws Exception {
assertThrows(InternalServerErrorException.class, () -> resource.doUpdateJob(emptyTransaction));
}

private TransactionType findJobTypeWithDifferentIdAndAmount(UkelonnService ukelonn, Integer transactionTypeId, double amount) {
return getJobtypes().stream().filter(t->!(t.id() == transactionTypeId)).filter(t->t.transactionAmount() != amount).toList().get(0);
private TransactionType findJobTypeWithDifferentIdAndAmount(Integer transactionTypeId, double amount) {
return getJobtypes().stream().filter(t->t.id() != transactionTypeId).filter(t->t.transactionAmount() != amount).toList().get(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class JobtypeListTest {

@Test
void testGetJobtypes() throws Exception {
void testGetJobtypes() {
// Create the resource that is to be tested
var resource = new JobtypeList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import no.priv.bang.ukelonn.beans.LocaleBean;

class LocalizationResourceTest {
private final static Locale NB_NO = Locale.forLanguageTag("nb-no");
private static final Locale NB_NO = Locale.forLanguageTag("nb-no");

@Test
void testDefaultLocale() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ void testLoginWithUnexpectedException() {
// Create the servlet and do the login
Login resource = new Login();
resource.setLogservice(logservice);
assertThrows(InternalServerErrorException.class, () -> {
resource.doLogin(credentials);
});
assertThrows(InternalServerErrorException.class, () -> resource.doLogin(credentials));
}

/**
Expand Down Expand Up @@ -251,7 +249,7 @@ void testGetLoginStateWhenLoggedIn() throws Exception {
* @throws Exception
*/
@Test
void testGetLoginStateWhenNotLoggedIn() throws Exception {
void testGetLoginStateWhenNotLoggedIn() {
// Set up the request
HttpSession session = mock(HttpSession.class);
HttpServletRequest request = mock(HttpServletRequest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LogoutTest extends ServletTestBase {
}

@Test
void testLogoutOk() throws Exception {
void testLogoutOk() {
// Set up the request
var request = mock(HttpServletRequest.class);
var session = mock(HttpSession.class);
Expand Down Expand Up @@ -64,7 +64,7 @@ void testLogoutOk() throws Exception {
* @throws Exception
*/
@Test
void testLogoutNotLoggedIn() throws Exception {
void testLogoutNotLoggedIn() {
// Set up the request and response used to do the login
var request = mock(HttpServletRequest.class);
var response = mock(HttpServletResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class PaymenttypeListTest {

@Test
void testGetPaymenttypes() throws Exception {
void testGetPaymenttypes() {
// Create the resource that is to be tested
var resource = new PaymenttypeList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class RegisterPaymentTest {

@Test
void testRegisterPayment() throws Exception {
void testRegisterPayment() {
// Create the request
var account = getJadAccount();
var originalBalance = account.balance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void testGetWithSqlException() throws Exception {
useradmin.setLogservice(logservice);

// Do a get operation that will fail
assertThrows(InternalServerErrorException.class, () -> resource.get());
assertThrows(InternalServerErrorException.class, resource::get);
}

}

0 comments on commit b331b92

Please sign in to comment.