-1

I am using this project (https://github.com/royclarkson/spring-rest-service-oauth) as server for my project. But I simply just want to add some attributes inside the User class, Ii also changed the import.sql. I changed "name" (did the refactoring for the getter and setter too) to "firstName" and add another "lastName" (and add the respective getter and setters).

@NotEmpty
private String firstName;
@NotEmpty
private String lastName;

And I also changed the import.sql to:

insert into user(id, firstName, lastName, login, password) values (1,'Roy','Smith','roy','pass');

insert into user(id, firstName, lastName, login, password) values (2,'Craig','Jones','craig','pass');

insert into user(id, firstName, lastName, login, password) values (3,'Greg','Robinson','greg','pass');

Then when I run my test cases, they all failed! For example if I run "greetingAuthorized" test case inside GreetingControllerTest.java, I get this error:

java.lang.AssertionError: Status expected:<200> but was:<400>
    at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:60)
    at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:89)
    at org.springframework.test.web.servlet.result.StatusResultMatchers$10.match(StatusResultMatchers.java:653)
    at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:152)
    at org.radiation.therapy.integration.test.GreetingControllerTest.getAccessToken(GreetingControllerTest.java:96)
    at org.radiation.therapy.integration.test.GreetingControllerTest.greetingAuthorized(GreetingControllerTest.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Why? I just change some attributes in User, my test cases cannot run. I did restart the server. Is there any configurations that I missed?

Update

I put my source code inside this zip file. This version only changed "name" to "firstName" and the problem shows up.

halfer
  • 19,824
  • 17
  • 99
  • 186
yeeen
  • 4,911
  • 11
  • 52
  • 73
  • and how does changing the attribute relate to that failed test? because you present no information that people can relate to ... what is 200, 400 comparing and how does that relate to this "attribute"? – Neil Stockton Oct 18 '15 at 12:20
  • This line is failing: Line 95: `.andExpect(status().isOk())`. As you can see, you expect the response to be OK which is 200, but you get 400 Bad Request. That might help you with debugging. – Ish Oct 18 '15 at 12:24
  • @NeilStockton Cos before changing it the tests all passed. I reverted back and tried many times. – yeeen Oct 18 '15 at 12:27
  • @Ish It doesn't help... why did i get the bad request i also dk. I change back and forth and is really cos of those attributes change that break the project. – yeeen Oct 18 '15 at 12:31
  • 1
    We have no idea what the test does, since you didn't post code. So we can't help. – JB Nizet Oct 18 '15 at 12:35
  • @JB Nizet Hi, the code is inside here: https://github.com/royclarkson/spring-rest-service-oauth I only refactor "name" to be "firstName" and its getter and setter, as well as added "lastname". And change import.sql to as above. N the project broke. – yeeen Oct 18 '15 at 12:36
  • Still it is hard to help on such a question. You expect people to turn to a different web site, dig into that source, and more: dig into the whole environment with its tests and so on. My suggestion: turn back to the "initial" content when the test passes. Then go in, make exactly one change at a time, and rerun the tests - to exactly understand which changes causes the breakage. And I really mean: do update exactly one thing of code / SQL / whatever at a time. – GhostCat Oct 18 '15 at 12:51
  • @Jägermeister, I have to agree. Btw, OP said he updated the properties of User entity. But I don't see it here. https://github.com/royclarkson/spring-rest-service-oauth/blob/master/src/main/java/hello/data/User.java – Ish Oct 18 '15 at 12:57
  • @Ish I didn't commit into the repository. It is someone's else project not mine. Ok, I put my project with attribute changed here: https://dl.dropboxusercontent.com/u/4256111/spring-rest-service-oauth-master_problem.zip – yeeen Oct 18 '15 at 13:10
  • @Jägermeister I did revert back to the initial state, that's why I am so certain that it was the attribute that broke it. – yeeen Oct 18 '15 at 13:13
  • 1
    I understand that it is clear that some of the changes broke the thing. But the real point is: "adding the attribute" is not a single thing. You made multiple changes. And I am telling you: don't expect that other people find the solution in such a complicated puzzle. So you will have to figure it yourself. And the only way to get there is to do the smallest step possible; verify, continue. And so on. Until you know exactly which change causes the failure. – GhostCat Oct 18 '15 at 13:22
  • @Jägermeister I understand. I am really using the initial state of the project, ensured that it is running ok then make just 1 change only from 'name' to 'firstName' and it broke. I always did what u said for debugging, that is revert to initial state then change from there. I really don't understand why this breaks. I also updated the link to the problematic project. Pls help... – yeeen Oct 18 '15 at 13:24
  • @JBNizet I have updated the qn with my problematic code. Is just the original project with a minor change. That's why i didn't upload previously. The current version is after reverting everything to the original state and just made that 1 change. – yeeen Oct 18 '15 at 13:29

1 Answers1

-1

This is because capital letters (e.g. firstName) are not acceptable in a hibernate database column. Either you have it

@NotEmpty
private String first_name;

Or you define the column name explicitly

@Column(name = "first_name", nullable = false)
private String firstName;

Like in this example: http://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-part-two-crud/

Update: quoting from my friend whom I asked

"Mostly databases have case-insensitive object names so capital letters make no sense. Hibernate converts capital letter to '_ + small letter'. Hence what you see. You need to know this when you start writing SQL queries."

I also searched online regarding this: hibernate column name issues and https://www.genuitec.com/forums/topic/hibernate-generated-classes-don-t-keep-upper-case-letters/

halfer
  • 19,824
  • 17
  • 99
  • 186
yeeen
  • 4,911
  • 11
  • 52
  • 73
  • obviously capital letters ARE acceptable in database column names, and all RDBMS have particular default cases, and quoting requirements – Neil Stockton Oct 19 '15 at 07:03
  • @NeilStockton but i dk somehow using capital letters breaks the program. I use all small caps can alr. – yeeen Oct 19 '15 at 12:48
  • only you know your database, only you know the actual error message (from JDBC that the JPA provider uses), only you have the logs for your JPA provider. The fact is that RDBMS allow mixed case (often with quotes) – Neil Stockton Oct 19 '15 at 13:00
  • @NeilStockton different database stores column names differently. Pls refer to the update of my own reply to my qn. I provide quote fr my friend n links to support this. Thanks. – yeeen Oct 20 '15 at 00:44