Skip to content

Commit

Permalink
SAK-39989 Sitestats unit test modernization (sakaiproject#7998)
Browse files Browse the repository at this point in the history
  • Loading branch information
ern authored May 1, 2020
1 parent 5640d3f commit f00aaa3
Show file tree
Hide file tree
Showing 51 changed files with 2,513 additions and 4,113 deletions.
21 changes: 0 additions & 21 deletions sitestats/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
<!-- Project versions -->
<properties>
<commons-betwixt.version>0.8</commons-betwixt.version>
<easymock.version>3.4</easymock.version>
<h2.version>1.1.111</h2.version>
<mysql.version>5.1.25</mysql.version>
<!-- <ojdbc.version>10.2.0.2.0</ojdbc.version> -->
<fop.version>1.0</fop.version>
<jfreechart.version>1.0.19</jfreechart.version>
<sst.wicket.version>6.30.0</sst.wicket.version>
Expand Down Expand Up @@ -126,23 +122,6 @@
<artifactId>jfreechart</artifactId>
<version>${jfreechart.version}</version>
</dependency>
<!-- Testing dependencies -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!-- <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc14</artifactId> <version>${ojdbc.version}</version> </dependency> -->
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>${easymock.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
public interface SitePresenceTotal {

public void incrementTotalVisits();

/**
* This increments the visits and updates the last visit time from the passed presence.
* @param sp The SitePresence to update from.
*/
public void updateFrom(SitePresence sp);

public long getId();
public void setId(long id);
public String getUserId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,80 +24,36 @@
import org.sakaiproject.sitestats.api.SitePresence;
import org.sakaiproject.sitestats.api.SitePresenceTotal;

import lombok.Getter;
import lombok.Setter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Getter
@Setter
/**
* Like the SitePresence but it includes a total number of visits and when they last visited for a site/user.
* @see SitePresence
*/
@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@NoArgsConstructor
public class SitePresenceTotalImpl implements SitePresenceTotal, Serializable {

private static final long serialVersionUID = 1L;

@EqualsAndHashCode.Include
private long id;
private String siteId;
private String userId;
private int totalVisits;
private Date lastVisitTime;

public SitePresenceTotalImpl() {}

public SitePresenceTotalImpl(SitePresence sp) {

siteId = sp.getSiteId();
userId = sp.getUserId();
totalVisits = 1;
setLastVisitTime(sp.getDate());
}

public void updateFrom(SitePresence sp) {
incrementTotalVisits();
setLastVisitTime(sp.getDate());
lastVisitTime = sp.getLastVisitStartTime();
}

public void incrementTotalVisits() {
totalVisits += 1;
}

public boolean equals(Object o) {

if (o == null) {
return false;
}

if (!(o instanceof SitePresenceTotalImpl)) {
return false;
}

SitePresenceTotalImpl other = (SitePresenceTotalImpl) o;

return id == other.getId()
&& siteId.equals(other.getSiteId())
&& userId.equals(other.getUserId())
&& totalVisits == other.getTotalVisits()
&& lastVisitTime.equals(other.getLastVisitTime());
}

@Override
public int hashCode() {

if (siteId == null) {
return Integer.MIN_VALUE;
}

String hashStr = this.getClass().getName() + ":"
+ id
+ siteId.hashCode()
+ userId.hashCode()
+ totalVisits
+ lastVisitTime.hashCode();
return hashStr.hashCode();
}

public String toString(){
return siteId + " : " + userId + " : " + totalVisits + " : " + lastVisitTime;
}
}
10 changes: 3 additions & 7 deletions sitestats/sitestats-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@
<artifactId>mysql-connector-java</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc14</artifactId>
<scope>test</scope> </dependency> -->
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
Expand All @@ -242,11 +240,6 @@
<artifactId>ehcache-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand All @@ -264,6 +257,9 @@
<testResource>
<directory>src/test</directory>
</testResource>
<testResource>
<directory>src/webapp</directory>
</testResource>
</testResources>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@
import java.util.ArrayList;
import java.util.List;

import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DBHelper extends HibernateDaoSupport {

@Setter private ServerConfigurationService serverConfigurationService;
private boolean autoDdl = false;
private String dbVendor = null;
private boolean notifiedIndexesUpdate = false;
Expand Down Expand Up @@ -230,10 +233,10 @@ private void renameIndex(Connection c, String oldIndex, String newIndex, String

private String getDbVendor() {
String dialectStr = null;
if(ServerConfigurationService.getString("sitestats.db", "internal").equals("internal")) {
dialectStr = ServerConfigurationService.getString("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
if(serverConfigurationService.getString("sitestats.db", "internal").equals("internal")) {
dialectStr = serverConfigurationService.getString("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
}else{
dialectStr = ServerConfigurationService.getString("sitestats.externalDb.hibernate.dialect","org.hibernate.dialect.HSQLDialect");
dialectStr = serverConfigurationService.getString("sitestats.externalDb.hibernate.dialect","org.hibernate.dialect.HSQLDialect");
}
if(dialectStr.toLowerCase().contains("mysql")) {
return "mysql";
Expand All @@ -246,10 +249,10 @@ private String getDbVendor() {

public boolean getAutoDdl() {
boolean autoDdl = false;
if(ServerConfigurationService.getString("sitestats.db", "internal").equals("internal")) {
autoDdl = ServerConfigurationService.getBoolean("auto.ddl", true);
if(serverConfigurationService.getString("sitestats.db", "internal").equals("internal")) {
autoDdl = serverConfigurationService.getBoolean("auto.ddl", true);
}else{
autoDdl = ServerConfigurationService.getBoolean("sitestats.externalDb.auto.ddl", true);
autoDdl = serverConfigurationService.getBoolean("sitestats.externalDb.auto.ddl", true);
}
return autoDdl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
*/
package org.sakaiproject.sitestats.impl;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.util.Properties;

import javax.annotation.PreDestroy;
import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.springframework.orm.hibernate.AdditionalHibernateMappings;
Expand All @@ -28,10 +31,9 @@
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import org.springframework.transaction.PlatformTransactionManager;

import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.Properties;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SiteStatsPersistenceConfig {
Expand Down
Loading

0 comments on commit f00aaa3

Please sign in to comment.