Skip to content

Commit

Permalink
Merge branch 'user_management'
Browse files Browse the repository at this point in the history
  • Loading branch information
enhan committed May 12, 2012
2 parents 5422ba4 + 9f3c11f commit 81e5547
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 4 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Expand Up @@ -23,6 +23,7 @@
<neo4j.version>1.6</neo4j.version>
<spring.neo4j.version>2.0.1.RELEASE</spring.neo4j.version>
<hibernate.validator.version>4.2.0.Final</hibernate.validator.version>
<joda.version>2.1</joda.version>

</properties>

Expand Down Expand Up @@ -126,6 +127,12 @@
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda.version}</version>
</dependency>

<!-- ASPECTJ -->
<dependency>
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/eu/enhan/timelord/domain/config/AppConfig.java
Expand Up @@ -16,8 +16,18 @@
*/
package eu.enhan.timelord.domain.config;

import java.util.Set;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ConversionServiceFactoryBean;
import org.springframework.core.convert.converter.Converter;

import com.google.common.collect.Sets;

import eu.enhan.timelord.domain.util.DateTimeToStringConverter;
import eu.enhan.timelord.domain.util.StringToDateTimeConverter;

/**
* @author Emmanuel Nhan
Expand All @@ -26,5 +36,17 @@
@Configuration
@ComponentScan("eu.enhan.timelord.domain")
public class AppConfig {

@Bean
public ConversionServiceFactoryBean conversionService(){
ConversionServiceFactoryBean cf = new ConversionServiceFactoryBean();
Set<Converter<?, ?>> converters = Sets.newHashSet();
converters.add(new DateTimeToStringConverter());
converters.add(new StringToDateTimeConverter());
cf.setConverters(converters);

return cf;
}


}
10 changes: 9 additions & 1 deletion src/main/java/eu/enhan/timelord/domain/core/TimelordUser.java
Expand Up @@ -16,6 +16,7 @@
*/
package eu.enhan.timelord.domain.core;

import org.joda.time.DateTime;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.NodeEntity;

Expand All @@ -34,13 +35,14 @@ public class TimelordUser {
private String login;
private String password;
private String email;

private DateTime registrationDate;

public TimelordUser(String login, String password, String email) {
super();
this.login = login;
this.password = password;
this.email = email;
registrationDate = new DateTime();
}

public TimelordUser() {
Expand Down Expand Up @@ -85,6 +87,7 @@ public int hashCode() {
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + ((login == null) ? 0 : login.hashCode());
result = prime * result + ((password == null) ? 0 : password.hashCode());
result = prime * result + ((registrationDate == null) ? 0 : registrationDate.hashCode());
return result;
}

Expand Down Expand Up @@ -112,6 +115,11 @@ public boolean equals(Object obj) {
return false;
} else if (!password.equals(other.password))
return false;
if (registrationDate == null) {
if (other.registrationDate != null)
return false;
} else if (!registrationDate.equals(other.registrationDate))
return false;
return true;
}

Expand Down
@@ -0,0 +1,34 @@
/*
* This file is part of Timelord.
*
* Timelord is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Timelord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the Affero GNU General Public License
* along with Timemord. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.enhan.timelord.domain.util;

import org.joda.time.DateTime;
import org.springframework.core.convert.converter.Converter;

/**
* @author Emmanuel Nhan
*
*/
public class DateTimeToStringConverter implements Converter<DateTime, String> {


@Override
public String convert(DateTime source) {
return source.toString();
}

}
@@ -0,0 +1,34 @@
/*
* This file is part of Timelord.
*
* Timelord is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Timelord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the Affero GNU General Public License
* along with Timemord. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.enhan.timelord.domain.util;

import org.joda.time.DateTime;
import org.springframework.core.convert.converter.Converter;

/**
* @author Emmanuel Nhan
*
*/
public class StringToDateTimeConverter implements Converter<String, DateTime> {

@Override
public DateTime convert(String source) {
DateTime result = new DateTime(source);
return result;
}

}
Expand Up @@ -18,6 +18,8 @@

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.template.Neo4jOperations;
import org.springframework.test.context.ActiveProfiles;
Expand All @@ -38,8 +40,10 @@
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=AppConfig.class)
@ActiveProfiles("dev")
public class TimlordUserTest {
public class TimelordUserTest {

private static final Logger logger = LoggerFactory.getLogger(TimelordUserTest.class);

@Autowired
Neo4jOperations template;

Expand All @@ -48,8 +52,16 @@ public void testCreateUser(){

TimelordUser user = new TimelordUser("me", "password", "email@mail.com");
template.save(user);
TimelordUser user2 = template.findOne(user.getId(), TimelordUser.class);
assertEquals(user, user2);
logger.debug("User saved. Sleeping for 1s.");
try {
Thread.sleep(1000);
logger.debug("Wake up, try to get it back.");
TimelordUser user2 = template.findOne(user.getId(), TimelordUser.class);
assertEquals(user, user2);
} catch (InterruptedException e) {
e.printStackTrace();
}



}
Expand Down
@@ -0,0 +1,53 @@
/*
* This file is part of Timelord.
*
* Timelord is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Timelord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the Affero GNU General Public License
* along with Timemord. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.enhan.timelord.test.domain.util;

import org.joda.time.DateTime;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import eu.enhan.timelord.domain.util.DateTimeToStringConverter;
import eu.enhan.timelord.domain.util.StringToDateTimeConverter;

import static org.junit.Assert.*;

/**
* @author Emmanuel Nhan
*
*/
public class DateTimeConversionTest {

private static final Logger logger = LoggerFactory.getLogger(DateTimeConversionTest.class);

@Test
public void testConvertion(){
StringToDateTimeConverter stringToDate = new StringToDateTimeConverter();
DateTimeToStringConverter dateToString = new DateTimeToStringConverter();

DateTime time = new DateTime(2012, 2, 2, 10, 0);
String converted = dateToString.convert(time);
logger.debug("Converted value = {}.", converted);
DateTime restored = stringToDate.convert(converted);

assertEquals(time, restored);



}

}

0 comments on commit 81e5547

Please sign in to comment.