Repository: openmeetings Updated Branches: refs/heads/master c08491a3f -> 3dac8e2fe
http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestRoomService.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestRoomService.java b/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestRoomService.java deleted file mode 100644 index 2a552c1..0000000 --- a/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestRoomService.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License") + you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.openmeetings.test.webservice; - -import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED; -import static org.apache.openmeetings.util.OmFileHelper.getDefaultProfilePicture; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.UUID; - -import javax.ws.rs.core.Form; - -import org.apache.openmeetings.db.dto.basic.ServiceResult; -import org.apache.openmeetings.db.dto.file.FileItemDTO; -import org.apache.openmeetings.db.dto.room.RoomDTO; -import org.apache.openmeetings.db.dto.room.RoomFileDTO; -import org.apache.openmeetings.db.entity.file.BaseFileItem; -import org.apache.openmeetings.db.entity.room.Room; -import org.junit.Test; - -public class TestRoomService extends AbstractWebServiceTest { - public static final String ROOM_SERVICE_URL = BASE_SERVICES_URL + "/room"; - private static final long CAPACITY = 666L; - - @Test - public void testExternal() { - ServiceResult sr = login(); - String extId = UUID.randomUUID().toString(); - Room.Type type = Room.Type.presentation; - String name = "Unit Test Ext Room"; - String comment = "Unit Test Ext Room Comments"; - RoomDTO r = new RoomDTO(); - r.setType(type); - r.setName(name); - r.setComment(comment); - r.setCapacity(CAPACITY); - RoomDTO room = getClient(ROOM_SERVICE_URL).path(String.format("/%s/%s/%s", type, UNIT_TEST_EXT_TYPE, extId)) - .query("sid", sr.getMessage()) - .query("room", r.toString()) - .get(RoomDTO.class); - assertNotNull("Valid room should be returned", room); - assertNotNull("Room ID should be not empty", room.getId()); - - RoomDTO room1 = getClient(ROOM_SERVICE_URL).path(String.format("/%s/%s/%s", Room.Type.presentation, UNIT_TEST_EXT_TYPE, extId)) - .query("sid", sr.getMessage()) - .get(RoomDTO.class); - assertNotNull("Valid room should be returned", room1); - assertEquals("Same Room should be returned", room.getId(), room1.getId()); - } - - private static CallResult<RoomDTO> createAndValidate(RoomDTO r) { - return createAndValidate(null, r); - } - - private static CallResult<RoomDTO> createAndValidate(String sid, RoomDTO r) { - if (sid == null) { - ServiceResult sr = login(); - sid = sr.getMessage(); - } - RoomDTO room = getClient(ROOM_SERVICE_URL) - .query("sid", sid) - .type(APPLICATION_FORM_URLENCODED) - .post(new Form().param("room", r.toString()), RoomDTO.class); - assertNotNull("Valid room should be returned", room); - assertNotNull("Room ID should be not empty", room.getId()); - - RoomDTO room1 = getClient(ROOM_SERVICE_URL).path(String.format("/%s", room.getId())) - .query("sid", sid) - .get(RoomDTO.class); - assertNotNull("Valid room should be returned", room1); - assertEquals("Room with same ID should be returned", room.getId(), room1.getId()); - assertEquals("Room with same Name should be returned", r.getName(), room1.getName()); - assertEquals("Room with same ExternalType should be returned", r.getExternalType(), room1.getExternalType()); - assertEquals("Room with same ExternalId should be returned", r.getExternalId(), room1.getExternalId()); - //TODO check other fields - return new CallResult<>(sid, room1); - } - - @Test - public void testCreate1() { - String extId = UUID.randomUUID().toString(); - Room.Type type = Room.Type.presentation; - String name = "Unit Test Ext Room1"; - String comment = "Unit Test Ext Room Comments1"; - RoomDTO r = new RoomDTO(); - r.setType(type); - r.setName(name); - r.setComment(comment); - r.setCapacity(CAPACITY); - r.setExternalType(UNIT_TEST_EXT_TYPE); - r.setExternalId(extId); - - createAndValidate(r); - } - - @Test - public void testCreate2() { - Room.Type type = Room.Type.presentation; - String name = "Unit Test Ext Room2"; - String comment = "Unit Test Ext Room Comments2"; - RoomDTO r = new RoomDTO(); - r.setType(type); - r.setName(name); - r.setComment(comment); - r.setCapacity(CAPACITY); - - createAndValidate(r); - } - - @Test - public void testCreateWithFiles1() { - Room.Type type = Room.Type.presentation; - String name = "Unit Test Ext Room3"; - String comment = "Unit Test Ext Room Comments3"; - RoomDTO r = new RoomDTO(); - r.setType(type); - r.setName(name); - r.setComment(comment); - r.setCapacity(CAPACITY); - RoomFileDTO rf = new RoomFileDTO(); - rf.setFileId(-666L); //not existent - r.getFiles().add(rf); - - CallResult<RoomDTO> res = createAndValidate(r); - assertTrue("No room files should be added", res.getObj().getFiles().isEmpty()); - } - - @Test - public void testCreateWithFiles2() throws IOException { - //lets create real file - CallResult<FileItemDTO> fileCall = createVerifiedFile(getDefaultProfilePicture(), "img.jpg", BaseFileItem.Type.Image); - - Room.Type type = Room.Type.presentation; - String name = "Unit Test Ext Room4"; - String comment = "Unit Test Ext Room Comments4"; - RoomDTO r = new RoomDTO(); - r.setType(type); - r.setName(name); - r.setComment(comment); - r.setCapacity(CAPACITY); - - RoomFileDTO rf = new RoomFileDTO(); - rf.setFileId(fileCall.getObj().getId()); //not existent - r.getFiles().add(rf); - - CallResult<RoomDTO> res = createAndValidate(fileCall.getSid(), r); - assertFalse("Room files should NOT be empty", res.getObj().getFiles().isEmpty()); - } -} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestUserService.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestUserService.java b/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestUserService.java deleted file mode 100644 index 01861d3..0000000 --- a/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestUserService.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License") + you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.openmeetings.test.webservice; - -import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.Locale; -import java.util.Random; -import java.util.TimeZone; -import java.util.UUID; - -import javax.ws.rs.core.Form; -import javax.ws.rs.core.Response; - -import org.apache.openmeetings.db.dto.basic.ServiceResult; -import org.apache.openmeetings.db.dto.basic.ServiceResult.Type; -import org.apache.openmeetings.db.dto.room.RoomOptionsDTO; -import org.apache.openmeetings.db.dto.user.ExternalUserDTO; -import org.apache.openmeetings.db.dto.user.UserDTO; -import org.apache.openmeetings.db.entity.user.Address; -import org.apache.openmeetings.web.app.WebSession; -import org.apache.wicket.util.string.StringValue; -import org.junit.Test; - -public class TestUserService extends AbstractWebServiceTest { - @Test - public void invalidLoginTest() { - ServiceResult r = loginNoCheck("invalid-user", "bad pass"); - assertNotNull("Valid ServiceResult should be returned", r); - assertEquals("Login should NOT be successful", Type.ERROR.name(), r.getType()); - } - - @Test - public void loginTest() { - ServiceResult r = login(); - assertNotNull("Valid ServiceResult should be returned", r); - } - - @Test - public void hashTest() { - ServiceResult r = login(); - ExternalUserDTO user = new ExternalUserDTO(); - user.setExternalId("1"); - user.setExternalType("OmJunitTests"); - user.setEmail("[email protected]"); - user.setFirstname("First Name 1"); - user.setLastname("Last Name 1"); - user.setLogin("login1"); - RoomOptionsDTO options = new RoomOptionsDTO(); - options.setRoomId(5L); - options.setModerator(true); - Response resp = getClient(USER_SERVICE_URL) - .path("/hash") - .query("sid", r.getMessage()) - .form(new Form().param("user", user.toString()).param("options", options.toString())); - assertNotNull("Valid ServiceResult should be returned", resp); - assertEquals("Call should be successful", Response.Status.OK.getStatusCode(), resp.getStatus()); - ServiceResult r1 = resp.readEntity(ServiceResult.class); - assertEquals("OM Call should be successful", r1.getType(), Type.SUCCESS.name()); - - WebSession ws = WebSession.get(); - ws.checkHashes(StringValue.valueOf(r1.getMessage()), StringValue.valueOf("")); - assertTrue("Login via secure hash should be successful", ws.isSignedIn()); - } - - @Test - public void addUserTest() { - Random rnd = new Random(); - String[] tzList = TimeZone.getAvailableIDs(); - String tz = TimeZone.getTimeZone(tzList[rnd.nextInt(tzList.length)]).getID(); - ServiceResult r = login(); - UserDTO u = new UserDTO(); - String uuid = UUID.randomUUID().toString(); - u.setLogin("test" + uuid); - u.setPassword(createPass()); - u.setFirstname("testF" + uuid); - u.setLastname("testL" + uuid); - u.setAddress(new Address()); - u.getAddress().setEmail(uuid + "@local"); - u.getAddress().setCountry(Locale.getDefault().getCountry()); - u.setTimeZoneId(tz); - u.setExternalId(uuid); - u.setExternalType("OmJunitTests"); - UserDTO user = getClient(USER_SERVICE_URL) - .path("/") - .query("sid", r.getMessage()) - .type(APPLICATION_FORM_URLENCODED) - .post(new Form().param("user", u.toString()).param("confirm", "" + false), UserDTO.class); - assertNotNull("Valid UserDTO should be returned", user); - assertNotNull("Id should not be NULL", user.getId()); - assertEquals("OM Call should be successful", u.getLogin(), user.getLogin()); - assertEquals("OM Call should be successful", tz, user.getTimeZoneId()); - } -} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestWebConverters.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestWebConverters.java b/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestWebConverters.java deleted file mode 100644 index 31edf2e..0000000 --- a/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestWebConverters.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License") + you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.openmeetings.test.webservice; - -import static org.junit.Assert.assertEquals; - -import java.time.LocalDate; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.util.Calendar; -import java.util.Date; - -import org.apache.openmeetings.db.dto.user.UserDTO; -import org.apache.openmeetings.webservice.util.CalendarParamConverter; -import org.apache.openmeetings.webservice.util.DateParamConverter; -import org.junit.Test; - -import com.github.openjson.JSONObject; - -public class TestWebConverters { - @Test - public void testDateConverter() { - assertEquals("Null date should be parsed", null, DateParamConverter.get(null)); - assertEquals("Date should be parsed" - , Date.from(LocalDate.of(2017, 01, 15).atStartOfDay(ZoneId.systemDefault()).toInstant()) - , DateParamConverter.get("2017-01-15")); - assertEquals("Date should be parsed" - , Date.from(ZonedDateTime.of(2017, 01, 20, 20, 30, 03, 0, ZoneId.of("Europe/Moscow")).toInstant()) - , DateParamConverter.get("2017-01-20T20:30:03+0300")); - } - - @Test - public void testCalendarConverter() { - CalendarParamConverter c = new CalendarParamConverter(); - assertEquals("Null calendar should be parsed", null, c.fromString(null)); - Calendar cal = Calendar.getInstance(); - cal.setTime(Date.from(LocalDate.of(2017, 01, 15).atStartOfDay(ZoneId.systemDefault()).toInstant())); - assertEquals("Calendar should be parsed", cal, c.fromString("2017-01-15")); - } - - @Test - public void testUserConverter() { - assertEquals("Null UserDTO should be parsed", null, UserDTO.get((JSONObject)null)); - } -} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/user/TestUserContact.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/user/TestUserContact.java b/openmeetings-web/src/test/java/org/apache/openmeetings/user/TestUserContact.java new file mode 100644 index 0000000..d5c8343 --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/user/TestUserContact.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.user; + +import static org.apache.openmeetings.web.app.WebSession.getUserId; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.UUID; + +import org.apache.openmeetings.AbstractWicketTester; +import org.apache.openmeetings.db.dao.user.GroupDao; +import org.apache.openmeetings.db.dao.user.UserDao; +import org.apache.openmeetings.db.entity.user.GroupUser; +import org.apache.openmeetings.db.entity.user.User; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +public class TestUserContact extends AbstractWicketTester { + @Autowired + private UserDao userDao; + @Autowired + private GroupDao groupDao; + + @Test + public void testGetUser() { + assertNull("Null should be returned in case User does not exist", userDao.get(Long.MAX_VALUE)); + } + + @Test + public void createUserWithGroup() throws Exception { + String uuid = UUID.randomUUID().toString(); + User u = getUser(uuid); + u.getGroupUsers().add(new GroupUser(groupDao.get(1L), u)); + u = userDao.update(u, null); + assertTrue("Password should be set as expected", userDao.verifyPassword(u.getId(), createPass())); + + User u1 = userDao.get(u.getId()); + assertNotNull("Just created user should not be null", u1); + assertNotNull("Just created user should have non null org-users", u1.getGroupUsers()); + assertFalse("Just created user should have not empty org-users", u1.getGroupUsers().isEmpty()); + } + + @Test + public void testCreateUser() throws Exception { + String uuid = UUID.randomUUID().toString(); + User u = createUser(uuid); + assertTrue("Password should be set as expected", userDao.verifyPassword(u.getId(), createPass())); + } + + @Test + public void addContactByOwner() throws Exception { + login(null, null); + + List<User> users = userDao.getAllUsers(); + assertNotNull("User list should not be null ", users); + assertFalse("User list should not be empty ", users.isEmpty()); + + User contact = createUserContact(getUserId()); + String email = contact.getAddress().getEmail(); + List<User> l = userDao.get(email, false, 0, 9999); + // check that contact is visible for admin + assertNotNull("Contact list should not be null for admin ", l); + assertFalse("Contact list should not be empty for admin ", l.isEmpty()); + + // check that contact is visible for owner + l = userDao.get(email, 0, 9999, null, true, getUserId()); + assertTrue("Contact list should not be empty for owner ", !l.isEmpty()); + //delete contact + userDao.delete(contact, getUserId()); + l = userDao.get(email, false, 0, 9999); + assertTrue("Contact list should be empty after deletion", l.isEmpty()); + + User u = createUser(); + User u1 = createUser(); + contact = createUserContact(u.getId()); + email = contact.getAddress().getEmail(); + // check that contact is not visible for user that is not owner of this contact + l = userDao.get(email, 0, 9999, null, true, u1.getId()); + assertTrue("Contact list should be empty for another user", l.isEmpty()); + //delete contact + userDao.delete(contact, u.getId()); + l = userDao.get(email, false, 0, 9999); + assertTrue("Contact list should be empty after deletion", l.isEmpty()); + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/user/TestUserCount.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/user/TestUserCount.java b/openmeetings-web/src/test/java/org/apache/openmeetings/user/TestUserCount.java new file mode 100644 index 0000000..1a539fb --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/user/TestUserCount.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.user; + +import static org.apache.openmeetings.web.app.WebSession.getUserId; +import static org.junit.Assert.assertTrue; + +import org.apache.openmeetings.AbstractWicketTester; +import org.apache.openmeetings.db.dao.user.UserDao; +import org.apache.openmeetings.db.entity.user.User; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +public class TestUserCount extends AbstractWicketTester { + @Autowired + private UserDao userDao; + + @Test + public void testCountSearchUsers() throws Exception { + User u = createUser(); + assertTrue("Account of search users should be one", userDao.count(u.getFirstname()) == 1); + } + + @Test + public void testCountFilteredUsers() throws Exception { + User u = createUser(); + User contact = createUserContact(u.getId()); + assertTrue("Account of filtered user should be one", userDao.count(contact.getFirstname(), true, u.getId()) == 1); + } + + @Test + public void testCountUnfilteredUsers() throws Exception { + User u = createUser(); + createUserContact(u.getId()); + assertTrue("Account of unfiltered should be more then one", userDao.count("firstname", false, getUserId()) > 1); + } + + @Test + public void testCountAllUsers() { + assertTrue("Account of users should be positive", userDao.count() > 0); + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/user/TestUserGroup.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/user/TestUserGroup.java b/openmeetings-web/src/test/java/org/apache/openmeetings/user/TestUserGroup.java new file mode 100644 index 0000000..1892e13 --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/user/TestUserGroup.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.user; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.List; +import java.util.UUID; + +import org.apache.openmeetings.AbstractJUnitDefaults; +import org.apache.openmeetings.db.dao.user.GroupDao; +import org.apache.openmeetings.db.dao.user.GroupUserDao; +import org.apache.openmeetings.db.dao.user.UserDao; +import org.apache.openmeetings.db.entity.user.Group; +import org.apache.openmeetings.db.entity.user.GroupUser; +import org.apache.openmeetings.db.entity.user.User; +import org.apache.openmeetings.selenium.HeavyTests; +import org.apache.openmeetings.util.OmException; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.springframework.beans.factory.annotation.Autowired; + +public class TestUserGroup extends AbstractJUnitDefaults { + @Autowired + private GroupUserDao groupUserDao; + @Autowired + private GroupDao groupDao; + @Autowired + private UserDao userDao; + public static final String GROUP_NAME = "Test Group"; + + private User getValidUser() { + for (User u : userDao.getAllBackupUsers()) { + if (!u.isDeleted() && u.getGroupUsers().size() > 0) { + return u; + } + } + fail("Unable to find valid user"); + return null; //unreachable + } + + @Test + public void getUsersByGroupId() { + User u = getValidUser(); + Long groupId = u.getGroupUsers().get(0).getGroup().getId(); + List<GroupUser> ul = groupUserDao.get(groupId, 0, 9999); + assertTrue("Default Group should contain at least 1 user: " + ul.size(), ul.size() > 0); + + GroupUser ou = groupUserDao.getByGroupAndUser(groupId, u.getId()); + assertNotNull("Unable to find [group, user] pair - [" + groupId + "," + u.getId() + "]", ou); + } + + @Test + public void addGroup() { + Group g = new Group(); + g.setName(GROUP_NAME); + Long groupId = groupDao.update(g, null).getId(); //inserted by not checked + assertNotNull("New Group have valid id", groupId); + + List<GroupUser> ul = groupUserDao.get(groupId, 0, 9999); + assertTrue("New Group should contain NO users: " + ul.size(), ul.size() == 0); + } + + @Test + public void addUserWithoutGroup() throws Exception { + String uuid = UUID.randomUUID().toString(); + User u = getUser(uuid); + u = userDao.update(u, null); + assertNotNull("User successfully created", u.getId()); + checkEmptyGroup("dao.get()", userDao.get(u.getId())); + try { + checkEmptyGroup("dao.login()", userDao.login(u.getAddress().getEmail(), createPass())); + fail("User with no Group is unable to login"); + } catch (OmException e) { + assertTrue("Expected Om Exception", "error.nogroup".equals(e.getKey())); + } + checkEmptyGroup("dao.getByLogin(user)", userDao.getByLogin(u.getLogin(), u.getType(), u.getDomainId())); + } + + + @Test + public void addLdapUserWithoutGroup() throws Exception { + User u1 = getUser(); + u1.setType(User.Type.ldap); + u1.setDomainId(1L); + u1 = userDao.update(u1, null); + checkEmptyGroup("dao.getByLogin(ldap)", userDao.getByLogin(u1.getLogin(), u1.getType(), u1.getDomainId())); + } + + private static void checkEmptyGroup(String prefix, User u) { + assertNotNull(prefix + ":: Created user should be available", u); + assertNotNull(prefix + ":: List<GroupUser> for newly created user should not be null", u.getGroupUsers()); + assertTrue(prefix + ":: List<GroupUser> for newly created user should be empty", u.getGroupUsers().isEmpty()); + } + + @Test + @Category(HeavyTests.class) + public void add10kUsers() throws Exception { + List<Group> groups = groupDao.get(GROUP_NAME, 0, 1, null); + Group g = null; + if (groups == null || groups.isEmpty()) { + g = new Group(); + g.setName(GROUP_NAME); + g = groupDao.update(g, null); + } else { + g = groups.get(0); + } + for (int i = 0; i < 10000; ++i) { + User u = createUser(); + u.getGroupUsers().add(new GroupUser(g, u)); + userDao.update(u, null); + } + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/userdata/TestAuth.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/userdata/TestAuth.java b/openmeetings-web/src/test/java/org/apache/openmeetings/userdata/TestAuth.java new file mode 100644 index 0000000..0155624 --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/userdata/TestAuth.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.userdata; + +import org.apache.openmeetings.AbstractJUnitDefaults; +import org.apache.openmeetings.db.dao.server.SessiondataDao; +import org.apache.openmeetings.db.entity.server.Sessiondata; +import org.apache.openmeetings.util.crypt.CryptProvider; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +public class TestAuth extends AbstractJUnitDefaults { + @Autowired + private SessiondataDao sessionDao; + + @Test + public void testTestAuth() { + Sessiondata sessionData = sessionDao.create(1L, 1L); + + System.out.println("sessionData: " + sessionData.getSessionId()); + + String tTemp = CryptProvider.get().hash("test"); + + System.out.println("tTemp: " + tTemp); + + } + +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/userdata/TestLogin.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/userdata/TestLogin.java b/openmeetings-web/src/test/java/org/apache/openmeetings/userdata/TestLogin.java new file mode 100644 index 0000000..3f8ce5d --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/userdata/TestLogin.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.userdata; + +import static org.junit.Assert.assertNotNull; + +import org.apache.openmeetings.AbstractJUnitDefaults; +import org.apache.openmeetings.db.dao.user.UserDao; +import org.apache.openmeetings.db.entity.user.User; +import org.apache.openmeetings.util.OmException; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +public class TestLogin extends AbstractJUnitDefaults { + + @Autowired + private UserDao userDao; + + @Test + public void testTestLogin() throws OmException { + User us = userDao.login(username, userpass); + + assertNotNull("User is unable to login", us); + + //mService.getLanguageById(1); + + } + +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/util/TestStoredFile.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/util/TestStoredFile.java b/openmeetings-web/src/test/java/org/apache/openmeetings/util/TestStoredFile.java new file mode 100644 index 0000000..7091eff --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/util/TestStoredFile.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.util; + +import static org.apache.openmeetings.util.OmFileHelper.getDefaultProfilePicture; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + +import org.apache.openmeetings.AbstractJUnitDefaults; +import org.apache.openmeetings.util.StoredFile; +import org.junit.Test; + +public class TestStoredFile extends AbstractJUnitDefaults { + @Test + public void testJpeg() throws FileNotFoundException, IOException { + File f = getDefaultProfilePicture(); + for (String ext : new String[] {null, "txt", "png"}) { + StoredFile sf = new StoredFile("test image", ext, f); + assertTrue("Type should be detected as image", sf.isImage()); + assertTrue("Type should be detected as image", sf.isAsIs()); + } + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/web/LoginUI.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/web/LoginUI.java b/openmeetings-web/src/test/java/org/apache/openmeetings/web/LoginUI.java new file mode 100644 index 0000000..addb44d --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/web/LoginUI.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.web; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.apache.openmeetings.AbstractWicketTester; +import org.apache.openmeetings.web.app.WebSession; +import org.apache.openmeetings.web.pages.MainPage; +import org.apache.openmeetings.web.pages.auth.SignInPage; +import org.apache.wicket.feedback.ExactLevelFeedbackMessageFilter; +import org.apache.wicket.feedback.FeedbackMessage; +import org.apache.wicket.util.tester.FormTester; +import org.junit.Test; + +import com.googlecode.wicket.jquery.ui.widget.dialog.ButtonAjaxBehavior; + +public class LoginUI extends AbstractWicketTester { + @Test + public void testValidLogin() { + tester.startPage(MainPage.class); + tester.assertRenderedPage(SignInPage.class); + + FormTester formTester = tester.newFormTester("signin:signin"); + formTester.setValue("login", username); + formTester.setValue("pass", userpass); + formTester.submit("submit"); + + tester.assertNoErrorMessage(); + tester.assertRenderedPage(MainPage.class); + WebSession ws = (WebSession)tester.getSession(); + assertTrue("Login should be successful", ws.isSignedIn()); + } + + @Test + public void testEmptyLogin() { + tester.startPage(SignInPage.class); + tester.assertRenderedPage(SignInPage.class); + + FormTester formTester = tester.newFormTester("signin:signin"); + formTester.submit("submit"); + + assertEquals("There should be exactly 2 errors", 2, + tester.getFeedbackMessages(new ExactLevelFeedbackMessageFilter(FeedbackMessage.ERROR)).size()); + } + + + @Test + public void testEmptyRegister() { + tester.startPage(SignInPage.class); + tester.assertRenderedPage(SignInPage.class); + + ButtonAjaxBehavior b = getButtonBehavior("signin", "register"); + tester.executeBehavior(b); + FormTester formTester = tester.newFormTester("register:form"); + formTester.submit("submit"); + assertEquals("There should be exactly 7 errors", 7, + tester.getFeedbackMessages(new ExactLevelFeedbackMessageFilter(FeedbackMessage.ERROR)).size()); + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/web/app/TestOmAuthenticationStrategy.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/web/app/TestOmAuthenticationStrategy.java b/openmeetings-web/src/test/java/org/apache/openmeetings/web/app/TestOmAuthenticationStrategy.java new file mode 100644 index 0000000..377e9fa --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/web/app/TestOmAuthenticationStrategy.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.web.app; + +import static org.junit.Assert.assertEquals; + +import org.apache.openmeetings.db.entity.user.User; +import org.junit.Test; + +public class TestOmAuthenticationStrategy { + @Test + public void test() { + OmAuthenticationStrategy s = new OmAuthenticationStrategy(); + s.save(null, null, User.Type.oauth, null); + assertEquals(0, s.decode(null).length); + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/AbstractWebServiceTest.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/AbstractWebServiceTest.java b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/AbstractWebServiceTest.java new file mode 100644 index 0000000..1bf39a4 --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/AbstractWebServiceTest.java @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.webservice; + +import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED; +import static org.apache.openmeetings.db.util.ApplicationHelper.getWicketTester; +import static org.apache.openmeetings.util.OmFileHelper.getOmHome; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +import javax.ws.rs.core.Form; +import javax.ws.rs.core.MediaType; + +import org.apache.catalina.LifecycleState; +import org.apache.catalina.startup.Tomcat; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; +import org.apache.openmeetings.AbstractJUnitDefaults; +import org.apache.openmeetings.db.dto.basic.ServiceResult; +import org.apache.openmeetings.db.dto.basic.ServiceResult.Type; +import org.apache.openmeetings.db.dto.file.FileItemDTO; +import org.apache.openmeetings.db.dto.user.UserDTO; +import org.apache.openmeetings.db.entity.file.BaseFileItem; +import org.apache.openmeetings.db.entity.user.User; +import org.apache.openmeetings.web.app.WebSession; +import org.apache.openmeetings.webservice.util.AppointmentMessageBodyReader; +import org.apache.wicket.util.tester.WicketTester; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; + +public class AbstractWebServiceTest extends AbstractJUnitDefaults { + private static Tomcat tomcat; + public static final String CONTEXT = "/openmeetings"; + public static final String BASE_SERVICES_URL = "http://localhost:8080" + CONTEXT + "/services"; + public static final String USER_SERVICE_URL = BASE_SERVICES_URL + "/user"; + public static final String INFO_SERVICE_URL = BASE_SERVICES_URL + "/info"; + public static final String FILE_SERVICE_URL = BASE_SERVICES_URL + "/file"; + public static final String UNIT_TEST_EXT_TYPE = "om_unit_tests"; + public static final long TIMEOUT = 5 * 60 * 1000; + protected WicketTester tester; + + public static WebClient getClient(String url) { + WebClient c = WebClient.create(url, Arrays.asList(new AppointmentMessageBodyReader())) + .accept("application/json").type("application/json"); + HTTPClientPolicy p = WebClient.getConfig(c).getHttpConduit().getClient(); + p.setConnectionTimeout(TIMEOUT); + p.setReceiveTimeout(TIMEOUT); + return c; + } + + public static ServiceResult login() { + return login(username, userpass); + } + + public static ServiceResult loginNoCheck(String user, String pass) { + ServiceResult sr = getClient(USER_SERVICE_URL).path("/login").query("user", user).query("pass", pass) + .get(ServiceResult.class); + return sr; + } + + public static ServiceResult login(String user, String pass) { + ServiceResult sr = loginNoCheck(user, pass); + assertEquals("Login should be successful", Type.SUCCESS.name(), sr.getType()); + return sr; + } + + @BeforeClass + public static void initialize() throws Exception { + tomcat = new Tomcat(); + tomcat.setPort(8080); + File wd = Files.createTempDirectory("om" + UUID.randomUUID().toString()).toFile(); + tomcat.setBaseDir(wd.getCanonicalPath()); + tomcat.getHost().setAppBase(wd.getCanonicalPath()); + tomcat.getHost().setAutoDeploy(true); + tomcat.getHost().setDeployOnStartup(true); + tomcat.addWebapp(CONTEXT, getOmHome().getAbsolutePath()); + tomcat.start(); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + tester = getWicketTester(); + assertNotNull("Web session should not be null", WebSession.get()); + } + + @After + public void tearDown() { + if (tester != null) { + //can be null in case exception on initialization + tester.destroy(); + } + } + + @AfterClass + public static void destroy() throws Exception { + if (tomcat.getServer() != null && tomcat.getServer().getState() != LifecycleState.DESTROYED) { + if (tomcat.getServer().getState() != LifecycleState.STOPPED) { + tomcat.stop(); + } + tomcat.destroy(); + } + } + + public void webCreateUser(User u) { + ServiceResult r = login(); + UserDTO dto = new UserDTO(u); + dto.setPassword(createPass()); + UserDTO user = getClient(USER_SERVICE_URL) + .path("/") + .query("sid", r.getMessage()) + .type(APPLICATION_FORM_URLENCODED) + .post(new Form().param("user", dto.toString()).param("confirm", "" + false), UserDTO.class); + Assert.assertNotNull(user.getId()); + u.setId(user.getId()); + } + + public CallResult<FileItemDTO> createVerifiedFile(File fsFile, String name, BaseFileItem.Type type) throws IOException { + ServiceResult r = login(); + + FileItemDTO f1 = null; + try (InputStream is = new FileInputStream(fsFile)) { + FileItemDTO file = new FileItemDTO() + .setName(name) + .setHash(UUID.randomUUID().toString()) + .setType(type); + List<Attachment> atts = new ArrayList<>(); + atts.add(new Attachment("file", MediaType.APPLICATION_JSON, file)); + atts.add(new Attachment("stream", MediaType.APPLICATION_OCTET_STREAM, is)); + f1 = getClient(FILE_SERVICE_URL) + .path("/") + .query("sid", r.getMessage()) + .type(MediaType.MULTIPART_FORM_DATA_TYPE).postCollection(atts, Attachment.class, FileItemDTO.class); + assertNotNull("Valid FileItem should be returned", f1); + assertNotNull("Valid FileItem should be returned", f1.getId()); + } + return new CallResult<>(r.getMessage(), f1); + } + + public static class CallResult<T> { + private final String sid; + private final T obj; + + public CallResult(String sid, T obj) { + this.sid = sid; + this.obj = obj; + } + + public String getSid() { + return sid; + } + + public T getObj() { + return obj; + } + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestCalendarService.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestCalendarService.java b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestCalendarService.java new file mode 100644 index 0000000..44618a1 --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestCalendarService.java @@ -0,0 +1,308 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.webservice; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import javax.ws.rs.core.Form; +import javax.ws.rs.core.Response; + +import org.apache.openmeetings.db.dao.calendar.MeetingMemberDao; +import org.apache.openmeetings.db.dao.room.InvitationDao; +import org.apache.openmeetings.db.dao.room.RoomDao; +import org.apache.openmeetings.db.dao.user.GroupDao; +import org.apache.openmeetings.db.dao.user.UserDao; +import org.apache.openmeetings.db.dto.basic.ServiceResult; +import org.apache.openmeetings.db.dto.calendar.AppointmentDTO; +import org.apache.openmeetings.db.dto.calendar.MeetingMemberDTO; +import org.apache.openmeetings.db.entity.calendar.Appointment; +import org.apache.openmeetings.db.entity.calendar.MeetingMember; +import org.apache.openmeetings.db.entity.room.Room; +import org.apache.openmeetings.db.entity.user.GroupUser; +import org.apache.openmeetings.db.entity.user.User; +import org.apache.openmeetings.webservice.util.AppointmentParamConverter; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import com.github.openjson.JSONArray; +import com.github.openjson.JSONObject; + +public class TestCalendarService extends AbstractWebServiceTest { + public static final String CALENDAR_SERVICE_URL = BASE_SERVICES_URL + "/calendar"; + @Autowired + private GroupDao groupDao; + @Autowired + private RoomDao roomDao; + @Autowired + private MeetingMemberDao mmDao; + @Autowired + private InvitationDao invitationDao; + @Autowired + private UserDao userDao; + + private void actualTest(Room r) throws Exception { + String uuid = UUID.randomUUID().toString(); + User u = getUser(uuid); + u.getGroupUsers().add(new GroupUser(groupDao.get(1L), u)); + webCreateUser(u); + ServiceResult sr = login(u.getLogin(), createPass()); + + Date start = new Date(); + Appointment a = createAppointment(getAppointment(u, r, start, new Date(start.getTime() + ONE_HOUR))); + + AppointmentDTO app = getClient(CALENDAR_SERVICE_URL).path("/room/" + a.getRoom().getId()).query("sid", sr.getMessage()) + .get(AppointmentDTO.class); + assertNotNull("Valid DTO should be returned", app); + } + + @Test + public void testGetByAppRoom() throws Exception { + actualTest(null); + } + + @Test + public void testGetByPublicRoom() throws Exception { + actualTest(roomDao.get(5L)); //default public presentation room + } + + private static JSONObject createAppointment(String title) { + return new JSONObject() + .put("title", title) + .put("start", "2025-01-20T20:30:03+0300") + .put("end", "2025-01-20T21:30:03+0300") + .put("description", "Ð ÑÑÑкий ТеÑÑ") + .put("reminder", "email") + .put("room", new JSONObject() + .put("name", "test24") + .put("comment", "appointment test room") + .put("type", "conference") + .put("capacity", 15) + .put("appointment", true) + .put("isPublic", false) + .put("demo", false) + .put("closed", false) + .put("externalId", 10) + .put("externalType", "HuntingLabCMS") + .put("redirectUrl", "") + .put("moderated", true) + .put("allowUserQuestions", true) + .put("allowRecording", false) + .put("waitForRecording", false) + .put("audioOnly", true) + .put("topBarHidden", false) + .put("chatHidden", false) + .put("activitiesHidden", false) + .put("filesExplorerHidden", false) + .put("actionsMenuHidden", false) + .put("screenSharingHidden", false) + .put("whiteboardHidden", false)) + .put("languageId", 9) + .put("passwordProtected", false) + .put("connectedEvent", false) + .put("reminderEmailSend", false); + } + + private String loginNewUser() throws Exception { + String uuid = UUID.randomUUID().toString(); + User u = getUser(uuid); + u.getGroupUsers().add(new GroupUser(groupDao.get(1L), u)); + webCreateUser(u); + ServiceResult sr = login(u.getLogin(), createPass()); + return sr.getMessage(); + } + + private String createApp(String title) throws Exception { + JSONObject o = createAppointment(title); + + String sid = loginNewUser(); + + Response resp = getClient(CALENDAR_SERVICE_URL) + .path("/") + .query("sid", sid) + .form(new Form().param("appointment", o.toString())); + + assertNotNull("Valid AppointmentDTO should be returned", resp); + assertEquals("Call should be successful", Response.Status.OK.getStatusCode(), resp.getStatus()); + AppointmentDTO dto = resp.readEntity(AppointmentDTO.class); + assertNotNull("Valid DTO should be returned", dto); + assertNotNull("DTO id should be valid", dto.getId()); + + return sid; + } + + @Test + public void testCreate() throws Exception { + createApp("test"); + } + + @Test + public void testDelete() { + ServiceResult sr = login(); + Response resp = getClient(CALENDAR_SERVICE_URL) + .path("/" + Long.MAX_VALUE) //non-existent ID + .query("sid", sr.getMessage()) + .delete(); + + assertNotEquals("Call should NOT be successful", Response.Status.OK.getStatusCode(), resp.getStatus()); + } + + @Test + public void testCreateWithOmMm() throws Exception { + JSONObject o = createAppointment("test") + .put("meetingMembers", new JSONArray() + .put(new JSONObject().put("user", new JSONObject() + .put("id", 1)))); + + String uuid = UUID.randomUUID().toString(); + User u = getUser(uuid); + u.getGroupUsers().add(new GroupUser(groupDao.get(1L), u)); + u = createUser(u); + ServiceResult sr = login(u.getLogin(), createPass()); + + Response resp = getClient(CALENDAR_SERVICE_URL) + .path("/") + .query("sid", sr.getMessage()) + .form(new Form().param("appointment", o.toString())); + + assertNotNull("Valid AppointmentDTO should be returned", resp); + assertEquals("Call should be successful", Response.Status.OK.getStatusCode(), resp.getStatus()); + AppointmentDTO dto = resp.readEntity(AppointmentDTO.class); + assertNotNull("Valid DTO should be returned", dto); + assertNotNull("DTO id should be valid", dto.getId()); + } + + private static AppointmentDTO createEventWithGuests(String sid) throws Exception { + JSONObject o = createAppointment("test") + .put("meetingMembers", new JSONArray() + .put(new JSONObject().put("user", new JSONObject() + .put("firstname", "John 1") + .put("lastname", "Doe") + .put("address", new JSONObject().put("email", "[email protected]")) + )) + .put(new JSONObject().put("user", new JSONObject() + .put("firstname", "John 2") + .put("lastname", "Doe") + .put("address", new JSONObject().put("email", "[email protected]")) + )) + ); + + Response resp = getClient(CALENDAR_SERVICE_URL) + .path("/") + .query("sid", sid) + .form(new Form().param("appointment", o.toString())); + + assertNotNull("Valid AppointmentDTO should be returned", resp); + assertEquals("Call should be successful", Response.Status.OK.getStatusCode(), resp.getStatus()); + AppointmentDTO dto = resp.readEntity(AppointmentDTO.class); + assertNotNull("Valid DTO should be returned", dto); + assertNotNull("DTO id should be valid", dto.getId()); + assertEquals("DTO should have 2 attendees", 2, dto.getMeetingMembers().size()); + for (MeetingMemberDTO mm : dto.getMeetingMembers()) { + assertNotNull("Email should be valid", mm.getUser().getAddress().getEmail()); + } + + return dto; + } + + @Test + public void testCreateWithGuests() throws Exception { + String sid = loginNewUser(); + AppointmentDTO dto = createEventWithGuests(sid); + + //try to change MM list + JSONObject o1 = AppointmentParamConverter.json(dto) + .put("meetingMembers", new JSONArray() + .put(new JSONObject().put("user", new JSONObject() + .put("id", 1)))); + + Response resp = getClient(CALENDAR_SERVICE_URL) + .path("/") + .query("sid", sid) + .form(new Form().param("appointment", o1.toString())); + + assertNotNull("Valid AppointmentDTO should be returned", resp); + assertEquals("Call should be successful", Response.Status.OK.getStatusCode(), resp.getStatus()); + dto = resp.readEntity(AppointmentDTO.class); + assertNotNull("Valid DTO should be returned", dto); + assertNotNull("DTO id should be valid", dto.getId()); + assertEquals("DTO should have 1 attendees", 1, dto.getMeetingMembers().size()); + } + + @Test + public void testCreateWithGuestsCleanOne() throws Exception { + String sid = loginNewUser(); + AppointmentDTO dto = createEventWithGuests(sid); + List<MeetingMemberDTO> initialList = new ArrayList<>(dto.getMeetingMembers()); + MeetingMember mm = mmDao.get(initialList.get(initialList.size() - 1).getId()); + Long mmId = mm.getId(), mmUserId = mm.getUser().getId(); + String hash = mm.getInvitation().getHash(); + dto.getMeetingMembers().remove(initialList.size() - 1); + + //try to change MM list + JSONObject o = AppointmentParamConverter.json(dto); + Response resp = getClient(CALENDAR_SERVICE_URL) + .path("/") + .query("sid", sid) + .form(new Form().param("appointment", o.toString())); + + assertNotNull("Valid AppointmentDTO should be returned", resp); + assertEquals("Call should be successful", Response.Status.OK.getStatusCode(), resp.getStatus()); + dto = resp.readEntity(AppointmentDTO.class); + assertNotNull("Valid DTO should be returned", dto); + assertNotNull("DTO id should be valid", dto.getId()); + assertEquals("DTO should have 1 attendees", 1, dto.getMeetingMembers().size()); + + assertNull("Meeting member should deleted", mmDao.get(mmId)); + assertNull("Invitation should deleted", invitationDao.getByHash(hash, true, false)); + User uc = userDao.get(mmUserId); + assertNotNull("Meeting member user should not be deleted", uc); + assertFalse("Meeting member user should not be deleted", uc.isDeleted()); + } + + @Test + public void testGetByTitle() throws Exception { + String title = "title" + UUID.randomUUID().toString(); + String sid = createApp(title); + @SuppressWarnings("unchecked") + List<AppointmentDTO> list = (List<AppointmentDTO>)getClient(CALENDAR_SERVICE_URL) + .path(String.format("/title/%s", title)) + .query("sid", sid) + .getCollection(AppointmentDTO.class); + + assertEquals("List of one item should be returned", 1, list.size()); + assertEquals("Title should match", title, list.get(0).getTitle()); + + title = UUID.randomUUID().toString(); + @SuppressWarnings("unchecked") + List<AppointmentDTO> list1 = (List<AppointmentDTO>)getClient(CALENDAR_SERVICE_URL) + .path(String.format("/title/%s", title)) + .query("sid", sid) + .getCollection(AppointmentDTO.class); + assertEquals("None items should be returned", 0, list1.size()); + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestFileService.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestFileService.java b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestFileService.java new file mode 100644 index 0000000..c662950 --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestFileService.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.webservice; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +import org.apache.openmeetings.db.dto.basic.ServiceResult; +import org.apache.openmeetings.db.dto.file.FileExplorerObject; +import org.apache.openmeetings.db.dto.file.FileItemDTO; +import org.apache.openmeetings.db.entity.file.BaseFileItem; +import org.apache.openmeetings.util.NonJenkinsTests; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class TestFileService extends AbstractWebServiceTest { + + @Test + @Category(NonJenkinsTests.class) + public void addFileTest() throws IOException { + File img = null; + try { + img = File.createTempFile("omtest", ".jpg"); + final Integer width = 150; + final Integer height = 100; + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + Graphics g = image.getGraphics(); + g.drawString("Hello World!!!", 10, 20); + ImageIO.write(image, "jpg", img); + CallResult<FileItemDTO> cr = createVerifiedFile(img, "test.txt", BaseFileItem.Type.Presentation); + assertEquals("Type should be Image", BaseFileItem.Type.Image, cr.getObj().getType()); + assertEquals("Width should be determined", width, cr.getObj().getWidth()); + assertEquals("Height should be Image", height, cr.getObj().getHeight()); + } finally { + if (img != null && img.exists()) { + img.delete(); + } + } + } + + @Test + public void testGetRoom() { + ServiceResult r = login(); + FileExplorerObject fo = getClient(FILE_SERVICE_URL) + .path("/room/5") + .query("sid", r.getMessage()) + .get(FileExplorerObject.class); + assertNotNull(fo); + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestGroupService.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestGroupService.java b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestGroupService.java new file mode 100644 index 0000000..c93bcd4 --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestGroupService.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.webservice; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import javax.ws.rs.core.Response; + +import org.apache.openmeetings.db.dto.basic.ServiceResult; +import org.apache.openmeetings.db.dto.basic.ServiceResult.Type; +import org.junit.Test; + +public class TestGroupService extends AbstractWebServiceTest { + public static final String GROUP_SERVICE_URL = BASE_SERVICES_URL + "/group"; + + @Test + public void putTest() { + ServiceResult r = login(); + Response resp = getClient(GROUP_SERVICE_URL) + .path("/") + .query("sid", r.getMessage()).put(""); + assertEquals("Call should NOT be successful", Response.Status.METHOD_NOT_ALLOWED.getStatusCode(), resp.getStatus()); + } + + @Test + public void addRemoveTest() { + ServiceResult r = login(); + Long groupId = -1L; + { + Response resp = getClient(GROUP_SERVICE_URL) + .path("/") + .query("sid", r.getMessage()).query("name", "Test Group").post(""); + assertNotNull("Valid ServiceResult should be returned", resp); + assertEquals("Call should be successful", Response.Status.OK.getStatusCode(), resp.getStatus()); + ServiceResult r1 = resp.readEntity(ServiceResult.class); + assertEquals("OM Call should be successful", r1.getType(), Type.SUCCESS.name()); + groupId = Long.valueOf(r1.getMessage()); + } + //delete group created + { + Response resp = getClient(GROUP_SERVICE_URL) + .path("/" + groupId) + .query("sid", r.getMessage()).delete(); + assertNotNull("Valid ServiceResult should be returned", resp); + assertEquals("Call should be successful", Response.Status.OK.getStatusCode(), resp.getStatus()); + ServiceResult r1 = resp.readEntity(ServiceResult.class); + assertEquals("OM Call should be successful", r1.getType(), Type.SUCCESS.name()); + } + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestRecordingService.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestRecordingService.java b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestRecordingService.java new file mode 100644 index 0000000..a87a722 --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestRecordingService.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.webservice; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Collection; +import java.util.UUID; + +import org.apache.openmeetings.db.dao.record.RecordingDao; +import org.apache.openmeetings.db.dto.basic.ServiceResult; +import org.apache.openmeetings.db.dto.record.RecordingDTO; +import org.apache.openmeetings.db.entity.record.Recording; +import org.apache.openmeetings.db.entity.user.User; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +public class TestRecordingService extends AbstractWebServiceTest { + public static final String RECORD_SERVICE_URL = BASE_SERVICES_URL + "/record"; + @Autowired + private RecordingDao recordingDao; + + private User getExternalUser() throws Exception { + String uuid = UUID.randomUUID().toString(); + User u = getUser(uuid); + u.setExternalType(UNIT_TEST_EXT_TYPE); + u.setExternalId(uuid); + webCreateUser(u); + return u; + } + + @Test + public void testExternal() throws Exception { + User u = getExternalUser(); + Recording r = new Recording(); + r.setInsertedBy(u.getId()); + r.setComment("Created by Unit Tests"); + r.setRoomId(5L); + r = recordingDao.update(r); + ServiceResult sr = login(); + Collection<? extends RecordingDTO> recs = getClient(RECORD_SERVICE_URL).path("/" + UNIT_TEST_EXT_TYPE).query("sid", sr.getMessage()) + .getCollection(RecordingDTO.class); + assertNotNull("Valid collection should be returned", recs); + assertFalse("Collection of the recordings should not be empty", recs.isEmpty()); + boolean found = false; + for (RecordingDTO rdo : recs) { + if (r.getId().equals(rdo.getId())) { + //TODO check room, user + found = true; + break; + } + } + assertTrue("Just created recording was not found by the service", found); + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestRoomService.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestRoomService.java b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestRoomService.java new file mode 100644 index 0000000..0f2e68b --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestRoomService.java @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.webservice; + +import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED; +import static org.apache.openmeetings.util.OmFileHelper.getDefaultProfilePicture; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.UUID; + +import javax.ws.rs.core.Form; + +import org.apache.openmeetings.db.dto.basic.ServiceResult; +import org.apache.openmeetings.db.dto.file.FileItemDTO; +import org.apache.openmeetings.db.dto.room.RoomDTO; +import org.apache.openmeetings.db.dto.room.RoomFileDTO; +import org.apache.openmeetings.db.entity.file.BaseFileItem; +import org.apache.openmeetings.db.entity.room.Room; +import org.junit.Test; + +public class TestRoomService extends AbstractWebServiceTest { + public static final String ROOM_SERVICE_URL = BASE_SERVICES_URL + "/room"; + private static final long CAPACITY = 666L; + + @Test + public void testExternal() { + ServiceResult sr = login(); + String extId = UUID.randomUUID().toString(); + Room.Type type = Room.Type.presentation; + String name = "Unit Test Ext Room"; + String comment = "Unit Test Ext Room Comments"; + RoomDTO r = new RoomDTO(); + r.setType(type); + r.setName(name); + r.setComment(comment); + r.setCapacity(CAPACITY); + RoomDTO room = getClient(ROOM_SERVICE_URL).path(String.format("/%s/%s/%s", type, UNIT_TEST_EXT_TYPE, extId)) + .query("sid", sr.getMessage()) + .query("room", r.toString()) + .get(RoomDTO.class); + assertNotNull("Valid room should be returned", room); + assertNotNull("Room ID should be not empty", room.getId()); + + RoomDTO room1 = getClient(ROOM_SERVICE_URL).path(String.format("/%s/%s/%s", Room.Type.presentation, UNIT_TEST_EXT_TYPE, extId)) + .query("sid", sr.getMessage()) + .get(RoomDTO.class); + assertNotNull("Valid room should be returned", room1); + assertEquals("Same Room should be returned", room.getId(), room1.getId()); + } + + private static CallResult<RoomDTO> createAndValidate(RoomDTO r) { + return createAndValidate(null, r); + } + + private static CallResult<RoomDTO> createAndValidate(String sid, RoomDTO r) { + if (sid == null) { + ServiceResult sr = login(); + sid = sr.getMessage(); + } + RoomDTO room = getClient(ROOM_SERVICE_URL) + .query("sid", sid) + .type(APPLICATION_FORM_URLENCODED) + .post(new Form().param("room", r.toString()), RoomDTO.class); + assertNotNull("Valid room should be returned", room); + assertNotNull("Room ID should be not empty", room.getId()); + + RoomDTO room1 = getClient(ROOM_SERVICE_URL).path(String.format("/%s", room.getId())) + .query("sid", sid) + .get(RoomDTO.class); + assertNotNull("Valid room should be returned", room1); + assertEquals("Room with same ID should be returned", room.getId(), room1.getId()); + assertEquals("Room with same Name should be returned", r.getName(), room1.getName()); + assertEquals("Room with same ExternalType should be returned", r.getExternalType(), room1.getExternalType()); + assertEquals("Room with same ExternalId should be returned", r.getExternalId(), room1.getExternalId()); + //TODO check other fields + return new CallResult<>(sid, room1); + } + + @Test + public void testCreate1() { + String extId = UUID.randomUUID().toString(); + Room.Type type = Room.Type.presentation; + String name = "Unit Test Ext Room1"; + String comment = "Unit Test Ext Room Comments1"; + RoomDTO r = new RoomDTO(); + r.setType(type); + r.setName(name); + r.setComment(comment); + r.setCapacity(CAPACITY); + r.setExternalType(UNIT_TEST_EXT_TYPE); + r.setExternalId(extId); + + createAndValidate(r); + } + + @Test + public void testCreate2() { + Room.Type type = Room.Type.presentation; + String name = "Unit Test Ext Room2"; + String comment = "Unit Test Ext Room Comments2"; + RoomDTO r = new RoomDTO(); + r.setType(type); + r.setName(name); + r.setComment(comment); + r.setCapacity(CAPACITY); + + createAndValidate(r); + } + + @Test + public void testCreateWithFiles1() { + Room.Type type = Room.Type.presentation; + String name = "Unit Test Ext Room3"; + String comment = "Unit Test Ext Room Comments3"; + RoomDTO r = new RoomDTO(); + r.setType(type); + r.setName(name); + r.setComment(comment); + r.setCapacity(CAPACITY); + RoomFileDTO rf = new RoomFileDTO(); + rf.setFileId(-666L); //not existent + r.getFiles().add(rf); + + CallResult<RoomDTO> res = createAndValidate(r); + assertTrue("No room files should be added", res.getObj().getFiles().isEmpty()); + } + + @Test + public void testCreateWithFiles2() throws IOException { + //lets create real file + CallResult<FileItemDTO> fileCall = createVerifiedFile(getDefaultProfilePicture(), "img.jpg", BaseFileItem.Type.Image); + + Room.Type type = Room.Type.presentation; + String name = "Unit Test Ext Room4"; + String comment = "Unit Test Ext Room Comments4"; + RoomDTO r = new RoomDTO(); + r.setType(type); + r.setName(name); + r.setComment(comment); + r.setCapacity(CAPACITY); + + RoomFileDTO rf = new RoomFileDTO(); + rf.setFileId(fileCall.getObj().getId()); //not existent + r.getFiles().add(rf); + + CallResult<RoomDTO> res = createAndValidate(fileCall.getSid(), r); + assertFalse("Room files should NOT be empty", res.getObj().getFiles().isEmpty()); + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestUserService.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestUserService.java b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestUserService.java new file mode 100644 index 0000000..ed4ec1e --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestUserService.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.webservice; + +import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Locale; +import java.util.Random; +import java.util.TimeZone; +import java.util.UUID; + +import javax.ws.rs.core.Form; +import javax.ws.rs.core.Response; + +import org.apache.openmeetings.db.dto.basic.ServiceResult; +import org.apache.openmeetings.db.dto.basic.ServiceResult.Type; +import org.apache.openmeetings.db.dto.room.RoomOptionsDTO; +import org.apache.openmeetings.db.dto.user.ExternalUserDTO; +import org.apache.openmeetings.db.dto.user.UserDTO; +import org.apache.openmeetings.db.entity.user.Address; +import org.apache.openmeetings.web.app.WebSession; +import org.apache.wicket.util.string.StringValue; +import org.junit.Test; + +public class TestUserService extends AbstractWebServiceTest { + @Test + public void invalidLoginTest() { + ServiceResult r = loginNoCheck("invalid-user", "bad pass"); + assertNotNull("Valid ServiceResult should be returned", r); + assertEquals("Login should NOT be successful", Type.ERROR.name(), r.getType()); + } + + @Test + public void loginTest() { + ServiceResult r = login(); + assertNotNull("Valid ServiceResult should be returned", r); + } + + @Test + public void hashTest() { + ServiceResult r = login(); + ExternalUserDTO user = new ExternalUserDTO(); + user.setExternalId("1"); + user.setExternalType("OmJunitTests"); + user.setEmail("[email protected]"); + user.setFirstname("First Name 1"); + user.setLastname("Last Name 1"); + user.setLogin("login1"); + RoomOptionsDTO options = new RoomOptionsDTO(); + options.setRoomId(5L); + options.setModerator(true); + Response resp = getClient(USER_SERVICE_URL) + .path("/hash") + .query("sid", r.getMessage()) + .form(new Form().param("user", user.toString()).param("options", options.toString())); + assertNotNull("Valid ServiceResult should be returned", resp); + assertEquals("Call should be successful", Response.Status.OK.getStatusCode(), resp.getStatus()); + ServiceResult r1 = resp.readEntity(ServiceResult.class); + assertEquals("OM Call should be successful", r1.getType(), Type.SUCCESS.name()); + + WebSession ws = WebSession.get(); + ws.checkHashes(StringValue.valueOf(r1.getMessage()), StringValue.valueOf("")); + assertTrue("Login via secure hash should be successful", ws.isSignedIn()); + } + + @Test + public void addUserTest() { + Random rnd = new Random(); + String[] tzList = TimeZone.getAvailableIDs(); + String tz = TimeZone.getTimeZone(tzList[rnd.nextInt(tzList.length)]).getID(); + ServiceResult r = login(); + UserDTO u = new UserDTO(); + String uuid = UUID.randomUUID().toString(); + u.setLogin("test" + uuid); + u.setPassword(createPass()); + u.setFirstname("testF" + uuid); + u.setLastname("testL" + uuid); + u.setAddress(new Address()); + u.getAddress().setEmail(uuid + "@local"); + u.getAddress().setCountry(Locale.getDefault().getCountry()); + u.setTimeZoneId(tz); + u.setExternalId(uuid); + u.setExternalType("OmJunitTests"); + UserDTO user = getClient(USER_SERVICE_URL) + .path("/") + .query("sid", r.getMessage()) + .type(APPLICATION_FORM_URLENCODED) + .post(new Form().param("user", u.toString()).param("confirm", "" + false), UserDTO.class); + assertNotNull("Valid UserDTO should be returned", user); + assertNotNull("Id should not be NULL", user.getId()); + assertEquals("OM Call should be successful", u.getLogin(), user.getLogin()); + assertEquals("OM Call should be successful", tz, user.getTimeZoneId()); + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestWebConverters.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestWebConverters.java b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestWebConverters.java new file mode 100644 index 0000000..5bd544a --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/webservice/TestWebConverters.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") + you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openmeetings.webservice; + +import static org.junit.Assert.assertEquals; + +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Calendar; +import java.util.Date; + +import org.apache.openmeetings.db.dto.user.UserDTO; +import org.apache.openmeetings.webservice.util.CalendarParamConverter; +import org.apache.openmeetings.webservice.util.DateParamConverter; +import org.junit.Test; + +import com.github.openjson.JSONObject; + +public class TestWebConverters { + @Test + public void testDateConverter() { + assertEquals("Null date should be parsed", null, DateParamConverter.get(null)); + assertEquals("Date should be parsed" + , Date.from(LocalDate.of(2017, 01, 15).atStartOfDay(ZoneId.systemDefault()).toInstant()) + , DateParamConverter.get("2017-01-15")); + assertEquals("Date should be parsed" + , Date.from(ZonedDateTime.of(2017, 01, 20, 20, 30, 03, 0, ZoneId.of("Europe/Moscow")).toInstant()) + , DateParamConverter.get("2017-01-20T20:30:03+0300")); + } + + @Test + public void testCalendarConverter() { + CalendarParamConverter c = new CalendarParamConverter(); + assertEquals("Null calendar should be parsed", null, c.fromString(null)); + Calendar cal = Calendar.getInstance(); + cal.setTime(Date.from(LocalDate.of(2017, 01, 15).atStartOfDay(ZoneId.systemDefault()).toInstant())); + assertEquals("Calendar should be parsed", cal, c.fromString("2017-01-15")); + } + + @Test + public void testUserConverter() { + assertEquals("Null UserDTO should be parsed", null, UserDTO.get((JSONObject)null)); + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/3dac8e2f/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 5f3272e..1a8f43c 100644 --- a/pom.xml +++ b/pom.xml @@ -840,10 +840,6 @@ <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> - <configuration> - <destFile>${sonar.jacoco.reportPath}</destFile> - <append>true</append> - </configuration> <executions> <execution> <id>prepare-agent</id> @@ -1042,6 +1038,10 @@ <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.9</version> + <configuration> + <destFile>${sonar.jacoco.reportPath}</destFile> + <append>true</append> + </configuration> </plugin> <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
