Giter VIP home page Giter VIP logo

java-testingusermodel's Introduction

Project Testing User Model

A student that completes this project shows they can:

  • explain what automated testing is and why it is important
  • use JUnit to write, run, and interpret the output of unit tests for services with or without database access
  • use JUnit to write, run, and interpret the output of unit tests for controllers
  • implement Automated Integration Testing for REST APIs using JUnit and RestAssured

Introduction

This is a basic database scheme with users, user emails, and user roles. This Java Spring REST API application will provide endpoints for clients to read various data sets contained in the application's data.

Database layout

The data layout is as follows

  • User is the driving table.
  • Useremails have a Many-To-One relationship with User. Each User has many user email combinations. Each user email combination has only one User.
  • Roles have a Many-To-Many relationship with Users.

Image of Database Layout

Using the provided seed data, expand each endpoint below to see the output it generates.

http://localhost:2019/useremails/useremails
[
    {
        "useremailid": 5,
        "useremail": "[email protected]",
        "user": {
            "userid": 4,
            "username": "admin",
            "primaryemail": "[email protected]",
            "roles": [
                {
                    "role": {
                        "roleid": 3,
                        "name": "DATA"
                    }
                },
                {
                    "role": {
                        "roleid": 1,
                        "name": "ADMIN"
                    }
                },
                {
                    "role": {
                        "roleid": 2,
                        "name": "USER"
                    }
                }
            ]
        }
    },
    {
        "useremailid": 6,
        "useremail": "[email protected]",
        "user": {
            "userid": 4,
            "username": "admin",
            "primaryemail": "[email protected]",
            "roles": [
                {
                    "role": {
                        "roleid": 3,
                        "name": "DATA"
                    }
                },
                {
                    "role": {
                        "roleid": 1,
                        "name": "ADMIN"
                    }
                },
                {
                    "role": {
                        "roleid": 2,
                        "name": "USER"
                    }
                }
            ]
        }
    },
    {
        "useremailid": 8,
        "useremail": "[email protected]",
        "user": {
            "userid": 7,
            "username": "cinnamon",
            "primaryemail": "[email protected]",
            "roles": [
                {
                    "role": {
                        "roleid": 2,
                        "name": "USER"
                    }
                },
                {
                    "role": {
                        "roleid": 3,
                        "name": "DATA"
                    }
                }
            ]
        }
    },
    {
        "useremailid": 9,
        "useremail": "[email protected]",
        "user": {
            "userid": 7,
            "username": "cinnamon",
            "primaryemail": "[email protected]",
            "roles": [
                {
                    "role": {
                        "roleid": 2,
                        "name": "USER"
                    }
                },
                {
                    "role": {
                        "roleid": 3,
                        "name": "DATA"
                    }
                }
            ]
        }
    },
    {
        "useremailid": 10,
        "useremail": "[email protected]",
        "user": {
            "userid": 7,
            "username": "cinnamon",
            "primaryemail": "[email protected]",
            "roles": [
                {
                    "role": {
                        "roleid": 2,
                        "name": "USER"
                    }
                },
                {
                    "role": {
                        "roleid": 3,
                        "name": "DATA"
                    }
                }
            ]
        }
    },
    {
        "useremailid": 12,
        "useremail": "[email protected]",
        "user": {
            "userid": 11,
            "username": "barnbarn",
            "primaryemail": "[email protected]",
            "roles": [
                {
                    "role": {
                        "roleid": 2,
                        "name": "USER"
                    }
                }
            ]
        }
    }
]
http://localhost:2019/useremails/useremail/8
{
    "useremailid": 8,
    "useremail": "[email protected]",
    "user": {
        "userid": 7,
        "username": "cinnamon",
        "primaryemail": "[email protected]",
        "roles": [
            {
                "role": {
                    "roleid": 2,
                    "name": "USER"
                }
            },
            {
                "role": {
                    "roleid": 3,
                    "name": "DATA"
                }
            }
        ]
    }
}
DELETE http://localhost:2019/useremails/useremail/8
No Body Data

Status OK
PUT http://localhost:2019/useremails/useremail/9/email/[email protected]

OUTPUT

Status OK
http://localhost:2019/useremails/useremail/9
{
    "useremailid": 9,
    "useremail": "[email protected]",
    "user": {
        "userid": 7,
        "username": "cinnamon",
        "primaryemail": "[email protected]",
        "roles": [
            {
                "role": {
                    "roleid": 2,
                    "name": "USER"
                }
            },
            {
                "role": {
                    "roleid": 3,
                    "name": "DATA"
                }
            }
        ]
    }
}
POST http://localhost:2019/useremails/user/14/email/[email protected]

OUTPUT

Status CREATED

Location Header: http://localhost:2019/useremails/useremail/15
http://localhost:2019/useremails/useremail/15
{
    "useremailid": 15,
    "useremail": "[email protected]",
    "user": {
        "userid": 14,
        "username": "misskitty",
        "primaryemail": "[email protected]",
        "roles": [
            {
                "role": {
                    "roleid": 2,
                    "name": "USER"
                }
            }
        ]
    }
}

http://localhost:2019/roles/roles
[
    {
        "roleid": 1,
        "name": "ADMIN",
        "users": [
            {
                "user": {
                    "userid": 4,
                    "username": "admin",
                    "primaryemail": "[email protected]",
                    "useremails": [
                        {
                            "useremailid": 5,
                            "useremail": "[email protected]"
                        },
                        {
                            "useremailid": 6,
                            "useremail": "[email protected]"
                        }
                    ]
                }
            }
        ]
    },
    {
        "roleid": 2,
        "name": "USER",
        "users": [
            {
                "user": {
                    "userid": 14,
                    "username": "misskitty",
                    "primaryemail": "[email protected]",
                    "useremails": [
                        {
                            "useremailid": 15,
                            "useremail": "[email protected]"
                        }
                    ]
                }
            },
            {
                "user": {
                    "userid": 13,
                    "username": "puttat",
                    "primaryemail": "[email protected]",
                    "useremails": []
                }
            },
            {
                "user": {
                    "userid": 11,
                    "username": "barnbarn",
                    "primaryemail": "[email protected]",
                    "useremails": [
                        {
                            "useremailid": 12,
                            "useremail": "[email protected]"
                        }
                    ]
                }
            },
            {
                "user": {
                    "userid": 7,
                    "username": "cinnamon",
                    "primaryemail": "[email protected]",
                    "useremails": [
                        {
                            "useremailid": 9,
                            "useremail": "[email protected]"
                        },
                        {
                            "useremailid": 10,
                            "useremail": "[email protected]"
                        }
                    ]
                }
            },
            {
                "user": {
                    "userid": 4,
                    "username": "admin",
                    "primaryemail": "[email protected]",
                    "useremails": [
                        {
                            "useremailid": 5,
                            "useremail": "[email protected]"
                        },
                        {
                            "useremailid": 6,
                            "useremail": "[email protected]"
                        }
                    ]
                }
            }
        ]
    },
    {
        "roleid": 3,
        "name": "DATA",
        "users": [
            {
                "user": {
                    "userid": 4,
                    "username": "admin",
                    "primaryemail": "[email protected]",
                    "useremails": [
                        {
                            "useremailid": 5,
                            "useremail": "[email protected]"
                        },
                        {
                            "useremailid": 6,
                            "useremail": "[email protected]"
                        }
                    ]
                }
            },
            {
                "user": {
                    "userid": 7,
                    "username": "cinnamon",
                    "primaryemail": "[email protected]",
                    "useremails": [
                        {
                            "useremailid": 9,
                            "useremail": "[email protected]"
                        },
                        {
                            "useremailid": 10,
                            "useremail": "[email protected]"
                        }
                    ]
                }
            }
        ]
    }
]
http://localhost:2019/roles/role/3
{
    "roleid": 3,
    "name": "DATA",
    "users": [
        {
            "user": {
                "userid": 4,
                "username": "admin",
                "primaryemail": "[email protected]",
                "useremails": [
                    {
                        "useremailid": 5,
                        "useremail": "[email protected]"
                    },
                    {
                        "useremailid": 6,
                        "useremail": "[email protected]"
                    }
                ]
            }
        },
        {
            "user": {
                "userid": 7,
                "username": "cinnamon",
                "primaryemail": "[email protected]",
                "useremails": [
                    {
                        "useremailid": 9,
                        "useremail": "[email protected]"
                    },
                    {
                        "useremailid": 10,
                        "useremail": "[email protected]"
                    }
                ]
            }
        }
    ]
}
http://localhost:2019/roles/role/name/data
{
    "roleid": 3,
    "name": "DATA",
    "users": [
        {
            "user": {
                "userid": 4,
                "username": "admin",
                "primaryemail": "[email protected]",
                "useremails": [
                    {
                        "useremailid": 5,
                        "useremail": "[email protected]"
                    },
                    {
                        "useremailid": 6,
                        "useremail": "[email protected]"
                    }
                ]
            }
        },
        {
            "user": {
                "userid": 7,
                "username": "cinnamon",
                "primaryemail": "[email protected]",
                "useremails": [
                    {
                        "useremailid": 9,
                        "useremail": "[email protected]"
                    },
                    {
                        "useremailid": 10,
                        "useremail": "[email protected]"
                    }
                ]
            }
        }
    ]
}
POST http://localhost:2019/roles/role

DATA

{
    "name" : "ANewRole"
}

OUTPUT

Status CREATED

Location Header: http://localhost:2019/roles/role/16
http://localhost:2019/roles/role/name/anewrole
{
    "roleid": 16,
    "name": "ANEWROLE",
    "users": []
}
PUT http://localhost:2019/roles/role/16

DATA

{
    "name" : "ANewRole"
}

OUTPUT

Status OK

http://localhost:2019/users/users
[
    {
        "userid": 4,
        "username": "admin",
        "primaryemail": "[email protected]",
        "useremails": [
            {
                "useremailid": 5,
                "useremail": "[email protected]"
            },
            {
                "useremailid": 6,
                "useremail": "[email protected]"
            }
        ],
        "roles": [
            {
                "role": {
                    "roleid": 3,
                    "name": "DATA"
                }
            },
            {
                "role": {
                    "roleid": 1,
                    "name": "ADMIN"
                }
            },
            {
                "role": {
                    "roleid": 2,
                    "name": "USER"
                }
            }
        ]
    },
    {
        "userid": 7,
        "username": "cinnamon",
        "primaryemail": "[email protected]",
        "useremails": [
            {
                "useremailid": 9,
                "useremail": "[email protected]"
            },
            {
                "useremailid": 10,
                "useremail": "[email protected]"
            }
        ],
        "roles": [
            {
                "role": {
                    "roleid": 2,
                    "name": "USER"
                }
            },
            {
                "role": {
                    "roleid": 3,
                    "name": "DATA"
                }
            }
        ]
    },
    {
        "userid": 11,
        "username": "barnbarn",
        "primaryemail": "[email protected]",
        "useremails": [
            {
                "useremailid": 12,
                "useremail": "[email protected]"
            }
        ],
        "roles": [
            {
                "role": {
                    "roleid": 2,
                    "name": "USER"
                }
            }
        ]
    },
    {
        "userid": 13,
        "username": "puttat",
        "primaryemail": "[email protected]",
        "useremails": [],
        "roles": [
            {
                "role": {
                    "roleid": 2,
                    "name": "USER"
                }
            }
        ]
    },
    {
        "userid": 14,
        "username": "misskitty",
        "primaryemail": "[email protected]",
        "useremails": [
            {
                "useremailid": 15,
                "useremail": "[email protected]"
            }
        ],
        "roles": [
            {
                "role": {
                    "roleid": 2,
                    "name": "USER"
                }
            }
        ]
    }
]
http://localhost:2019/users/user/7
{
    "userid": 7,
    "username": "cinnamon",
    "primaryemail": "[email protected]",
    "useremails": [
        {
            "useremailid": 9,
            "useremail": "[email protected]"
        },
        {
            "useremailid": 10,
            "useremail": "[email protected]"
        }
    ],
    "roles": [
        {
            "role": {
                "roleid": 2,
                "name": "USER"
            }
        },
        {
            "role": {
                "roleid": 3,
                "name": "DATA"
            }
        }
    ]
}
http://localhost:2019/users/user/name/cinnamon
{
    "userid": 7,
    "username": "cinnamon",
    "primaryemail": "[email protected]",
    "useremails": [
        {
            "useremailid": 9,
            "useremail": "[email protected]"
        },
        {
            "useremailid": 10,
            "useremail": "[email protected]"
        }
    ],
    "roles": [
        {
            "role": {
                "roleid": 2,
                "name": "USER"
            }
        },
        {
            "role": {
                "roleid": 3,
                "name": "DATA"
            }
        }
    ]
}
http://localhost:2019/users/user/name/like/da
[]
POST http://localhost:2019/users/user

DATA

{
    "username": "Mojo",
    "primaryemail": "[email protected]",
    "password" : "Coffee123",
    "useremails": [
        {
            "useremail": "[email protected]"
        },
        {
            "useremail": "[email protected]"
        }
        ],
    "roles": [
        {
            "role": {
                "roleid": 1
            }
        },
        {
            "role": {
                "roleid": 2
            }
        }
    ]
}

OUTPUT

No Body Data

Location Header: http://localhost:2019/users/user/17
Status 201 Created
http://localhost:2019/users/user/name/mojo
PUT http://localhost:2019/users/user/14

DATA

{
    "username": "stumps",
    "primaryemail": "[email protected]",
    "password" : "EarlGray123",
    "useremails": [
        {
            "useremail": "[email protected]"
        },
        {
            "useremail": "[email protected]"
        }
        ],
    "roles": [
        {  
            "role": {
                "roleid": 3
            }
        },
        {  
            "role": {
                "roleid": 1
            }
        }
    ]
}

OUTPUT

No Body Data

Status OK
http://localhost:2019/users/user/name/stumps
{
    "userid": 16,
    "username": "stumps",
    "primaryemail": "[email protected]",
    "useremails": [
        {
            "useremailid": 19,
            "useremail": "[email protected]"
        },
        {
            "useremailid": 20,
            "useremail": "[email protected]"
        }
    ],
    "roles": [
        {
            "role": {
                "roleid": 1,
                "name": "ADMIN"
            }
        },
        {
            "role": {
                "roleid": 3,
                "name": "DATA"
            }
        }
    ]
}
PATCH http://localhost:2019/users/user/7

DATA

{
    "username": "cinabun",
    "primaryemail": "[email protected]",
    "useremails": [
    {
            "useremail": "[email protected]"
    },
    {
            "useremail": "[email protected]"
    },
    {
            "useremail": "[email protected]"
    }
    ]
}

OUTPUT

No Body Data

Status OK
http://localhost:2019/users/user/name/cinabun
{
    "userid": 7,
    "username": "cinabun",
    "primaryemail": "[email protected]",
    "useremails": [
        {
            "useremailid": 21,
            "useremail": "[email protected]"
        },
        {
            "useremailid": 22,
            "useremail": "[email protected]"
        },
        {
            "useremailid": 23,
            "useremail": "[email protected]"
        }
    ],
    "roles": [
        {
            "role": {
                "roleid": 2,
                "name": "USER"
            }
        },
        {
            "role": {
                "roleid": 3,
                "name": "DATA"
            }
        }
    ]
}
DELETE http://localhost:2019/users/user/14
No Body Data

Status OK

Instructions

  • Please fork and clone this repository.
  • This repository does have a starter project, so you must start with that application inside of the cloned repository folder. Regularly commit and push your code as appropriate.

MVP

  • Provide unit testing for the User Service (with or without database access). To reach MVP you must provide at least 75% coverage of the code in User Service as reported in IntelliJ
  • Provide unit testing for the User Controller without touching the database. To reach MVP you must provide at least 75% coverage of the code in User Controller as reported in IntelliJ

Stretch Goal

  • Provide integration testing for the User Controller. To reach the Stretch Goal you must provide 95% coverage of the code in User Controller as reported in IntelliJ
  • Provide unit testing for the User Service (with or without database access - pick the one you did not do for MVP). To reach the Stretch Goal you must provide 95% coverage of the code in User Service as reported in IntelliJ

java-testingusermodel's People

Contributors

jrmmba8314 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.