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

Branch status check #19

Open
wants to merge 16 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
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bin/
target/

.idea
*.iml

.settings
.project
.classpath

.DS_Store
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#configure travis
language: java

#build software
script: mvn test
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<modelVersion>4.0.0</modelVersion>
<groupId>net.apispark.webapi</groupId>
<artifactId>cicd</artifactId>
<artifactId>material-contacts-apispark</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
Expand Down
49 changes: 0 additions & 49 deletions server.qsmanu.iml

This file was deleted.

11 changes: 10 additions & 1 deletion src/main/java/net/apispark/webapi/representation/Contact.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;

import net.apispark.webapi.core.validation.ValidationErrors;
import net.apispark.webapi.representation.enums.Gender;

Expand All @@ -15,6 +16,7 @@ public class Contact implements Serializable {
private String lastName;
private String avatar;
private Date birthday;
private Gender gender;
private Boolean active;
private Integer rank;
private String companyId;
Expand Down Expand Up @@ -71,6 +73,14 @@ public void setBirthday(Date birthday) {
this.birthday = birthday;
}

public Gender getGender() {
return gender;
}

public void setGender(Gender gender) {
this.gender = gender;
}

public Boolean getActive() {
return active;
}
Expand All @@ -79,7 +89,6 @@ public void setActive(Boolean active) {
this.active = active;
}


public Integer getRank() {
return rank;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.apispark.webapi.representation.enums;

/**
* @author Manuel Boillod
*/
public enum Gender {
MAN, WOMAN
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.apispark.webapi.resource;

import net.apispark.webapi.db.ContactPersistence;
import net.apispark.webapi.representation.Contact;
import net.apispark.webapi.representation.enums.Gender;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;

/**
* @author Manuel Boillod
*/
public class ContactResourceTest {


@Test
public void added_contact_is_correct() throws Exception {
// given a contact
Contact contact = new Contact();
contact.setFirstName("John");
contact.setLastName("Smith");
contact.setGender(Gender.MAN);

// when added
Contact persistentContact = ContactPersistence.INSTANCE.addContact(contact);

// then returned contact has an id and is correct
assertThat(persistentContact, is(notNullValue()));
assertThat(persistentContact.getId(), is(notNullValue()));
assertThat(persistentContact.getFirstName(), is("John"));
assertThat(persistentContact.getLastName(), is("Smith"));
assertThat(persistentContact.getGender(), is(Gender.MAN));
}

@Test
public void added_contact_is_well_retrieved_by_id() throws Exception {
// given a added contact
Contact contact = new Contact();
contact.setFirstName("Sam");
contact.setLastName("Sung");
contact.setGender(Gender.MAN);
Contact persistentContact = ContactPersistence.INSTANCE.addContact(contact);
String contactId = persistentContact.getId();

// when retrieved by id
Contact retrievedContact = ContactPersistence.INSTANCE.getContact(contactId);

// then retrieved contact is correct
assertThat(retrievedContact, is(notNullValue()));
assertThat(retrievedContact.getId(), is(contactId));
assertThat(persistentContact.getFirstName(), is("Sam"));
assertThat(persistentContact.getLastName(), is("Sung"));
assertThat(persistentContact.getGender(), is(Gender.MAN));
}
}