Skip to content
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

'tarah agbokhana' #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion usermodel-initial/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<description>Demo project for Spring Boot</description>

<properties>
<java.version>11</java.version>
<java.version>14</java.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -77,6 +77,14 @@
</dependency>
<!-- Swagger Dependencies End -->

<!-- https://mvnrepository.com/artifact/io.rest-assured/spring-mock-mvc -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>

<!-- Security Dependencies Start -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -95,14 +103,37 @@
<version>2.3.6.RELEASE</version>
</dependency>
<!-- Security Dependencies End -->

<!-- &lt;!&ndash; Postgres SQL Dependencies Start &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>org.postgresql</groupId>-->
<!-- <artifactId>postgresql</artifactId>-->
<!-- </dependency>-->
</dependencies>

<build>
<!-- <finalName>tagbokhana-userModelApplication</finalName>-->
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- <plugin>-->
<!-- <groupId>com.heroku.sdk</groupId>-->
<!-- <artifactId>heroku-maven-plugin</artifactId>-->
<!-- <version>3.0.2</version>-->
<!-- <configuration>-->
<!-- <appName>${project.build.finalName}</appName>-->
<!-- <includeTarget>false</includeTarget>-->
<!-- <includes>-->
<!-- <include>${project.build.directory}/${project.build.finalName}.jar</include>-->
<!-- </includes>-->
<!-- <jdkVersion>${java.version}</jdkVersion>-->
<!-- <processTypes>-->
<!-- <web>java $JAVA_OPTS -Dserver.port=$PORT -jar target/${project.build.finalName}.jar</web>-->
<!-- </processTypes>-->
<!-- </configuration>-->
<!-- </plugin>-->
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.lambdaschool.usermodel.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -23,6 +24,11 @@
* after the application context has been loaded.
*/
@Transactional
@ConditionalOnProperty(
prefix = "command.line.runner",
value = "enabled",
havingValue = "true",
matchIfMissing = true)
@Component
public class SeedData
implements CommandLineRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public List<ValidationError> getConstraintViolation(Throwable cause)
// data validations get wrapped in other exceptions as we work through the Spring
// exception chain. Hence we have to search the entire Spring Exception Stack
// to see if we have any violation constraints.
while ((cause != null) && !(cause instanceof org.hibernate.exception.ConstraintViolationException || cause instanceof MethodArgumentNotValidException))
while ((cause != null) && !(cause instanceof ConstraintViolationException ||
cause instanceof MethodArgumentNotValidException))
{
System.out.println(cause.getClass()
.toString());
Expand All @@ -39,9 +40,9 @@ public List<ValidationError> getConstraintViolation(Throwable cause)
// we know that cause either null or an instance of ConstraintViolationException
if (cause != null)
{
if (cause instanceof org.hibernate.exception.ConstraintViolationException)
if (cause instanceof ConstraintViolationException)
{
org.hibernate.exception.ConstraintViolationException ex = (ConstraintViolationException) cause;
ConstraintViolationException ex = (ConstraintViolationException) cause;
ValidationError newVe = new ValidationError();
newVe.setCode(ex.getMessage());
newVe.setMessage(ex.getConstraintName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public UserDetails loadUserByUsername(String s)
{
throw new ResourceNotFoundException("Invalid username or password.");
}
return new org.springframework.security.core.userdetails.User(user.getUsername(),
return new org.springframework.security.core.userdetails.User(
user.getUsername(),
user.getPassword(),
user.getAuthority());
}
Expand Down
7 changes: 6 additions & 1 deletion usermodel-initial/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#local.run.db=H2
#local.run.db=POSTGRESQL
#
# Configurations useful for working with H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
#Allow Heroku to connect
#spring.h2.console.settings.web-allow-others=true
#
# We set a port that is not frequently used
server.port=${PORT:2019}
#
# Feature that determines what happens when no accessors are found for a type
# (and there are no annotations to indicate it is meant to be serialized).
spring.jackson.serialization.fail-on-empty-beans=false
spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false
#
# keeps a transaction inside of the same entity manager
# This property register an EntityManager to the current thread,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package com.lambdaschool.usermodel;

import com.github.javafaker.Faker;
import com.github.javafaker.service.FakeValuesService;
import com.github.javafaker.service.RandomService;
import com.lambdaschool.usermodel.models.*;
import com.lambdaschool.usermodel.services.RoleService;
import com.lambdaschool.usermodel.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Locale;

/**
* SeedData puts both known and random data into the database. It implements CommandLineRunner.
* <p>
* CoomandLineRunner: Spring Boot automatically runs the run method once and only once
* after the application context has been loaded.
*/
@Transactional
@ConditionalOnProperty(
prefix = "command.line.runner",
value = "enabled",
havingValue = "true",
matchIfMissing = true)
@Component
public class SeedData
implements CommandLineRunner
{
/**
* Connects the Role Service to this process
*/
@Autowired
RoleService roleService;

/**
* Connects the user service to this process
*/
@Autowired
UserService userService;

/**
* Generates test, seed data for our application
* First a set of known data is seeded into our database.
* Second a random set of data using Java Faker is seeded into our database.
* Note this process does not remove data from the database. So if data exists in the database
* prior to running this process, that data remains in the database.
*
* @param args The parameter is required by the parent interface but is not used in this process.
*/
@Transactional
@Override
public void run(String[] args) throws
Exception
{
userService.deleteAll();
roleService.deleteAll();
Role r1 = new Role("testadmin");
Role r2 = new Role("testuser");
Role r3 = new Role("testdata");

r1 = roleService.save(r1);
r2 = roleService.save(r2);
r3 = roleService.save(r3);

// admin, data, user
User u1 = new User("testadmin",
"password",
"[email protected]");
u1.getRoles()
.add(new UserRoles(u1,
r1));
u1.getRoles()
.add(new UserRoles(u1,
r2));
u1.getRoles()
.add(new UserRoles(u1,
r3));
u1.getUseremails()
.add(new Useremail(u1,
"[email protected]"));
u1.getUseremails()
.add(new Useremail(u1,
"[email protected]"));

userService.save(u1);

// data, user
User u2 = new User("testcinnamon",
"1234567",
"[email protected]");
u2.getRoles()
.add(new UserRoles(u2,
r2));
u2.getRoles()
.add(new UserRoles(u2,
r3));
u2.getUseremails()
.add(new Useremail(u2,
"[email protected]"));
u2.getUseremails()
.add(new Useremail(u2,
"[email protected]"));
u2.getUseremails()
.add(new Useremail(u2,
"[email protected]"));
userService.save(u2);

// user
User u3 = new User("testbarnbarn",
"ILuvM4th!",
"[email protected]");
u3.getRoles()
.add(new UserRoles(u3,
r2));
u3.getUseremails()
.add(new Useremail(u3,
"[email protected]"));
userService.save(u3);

User u4 = new User("testputtat",
"password",
"[email protected]");
u4.getRoles()
.add(new UserRoles(u4,
r2));
userService.save(u4);

User u5 = new User("testmisskitty",
"password",
"[email protected]");
u5.getRoles()
.add(new UserRoles(u5,
r2));
userService.save(u5);

if (false)
{
// using JavaFaker create a bunch of regular users
// https://www.baeldung.com/java-faker
// https://www.baeldung.com/regular-expressions-java

FakeValuesService fakeValuesService = new FakeValuesService(new Locale("en-US"),
new RandomService());
Faker nameFaker = new Faker(new Locale("en-US"));

for (int i = 0; i < 25; i++)
{
new User();
User fakeUser;

fakeUser = new User(nameFaker.name()
.username(),
"password",
nameFaker.internet()
.emailAddress());
fakeUser.getRoles()
.add(new UserRoles(fakeUser,
r2));
fakeUser.getUseremails()
.add(new Useremail(fakeUser,
fakeValuesService.bothify("????##@gmail.com")));
userService.save(fakeUser);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.lambdaschool.usermodel.controllers;

import org.junit.*;

import static org.junit.Assert.*;

public class UserControllerTestUnitTestNoDB {

@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}

@Test
public void listAllUsers() {
}

@Test
public void getUserById() {
}

@Test
public void getUserByName() {
}

@Test
public void getUserLikeName() {
}

@Test
public void addNewUser() {
}

@Test
public void updateFullUser() {
}

@Test
public void updateUser() {
}

@Test
public void deleteUserById() {
}

@Test
public void getCurrentUserInfo() {
}
}
Loading