Package org.apache.openmeetings.test.user

Source Code of org.apache.openmeetings.test.user.TestUserContact

/*
* 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.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.assertTrue;

import java.util.List;
import java.util.Random;

import org.apache.openmeetings.db.dao.user.AdminUserDao;
import org.apache.openmeetings.db.dao.user.UserDao;
import org.apache.openmeetings.db.entity.user.User;
import org.apache.openmeetings.test.AbstractWicketTester;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

public class TestUserContact extends AbstractWicketTester {
  @Autowired
  private AdminUserDao adminUserDao;

  @Autowired
  private UserDao usersDao;
 
  @Test
  public void addContactByOwner() throws Exception {
    login(null, null);
   
    List<User> users = adminUserDao.getAllUsers();
    assertNotNull("User list should not be null ", users);
    assertFalse("User list should not be empty ", users.isEmpty());
   
    Random random = new Random();
    User contact = createUserContact(random.nextInt(), getUserId());
    String email = contact.getAdresses().getEmail();
    List<User> l = adminUserDao.get(email, false);
    // 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 = usersDao.get(email, getUserId());
    assertTrue("Contact list should not be empty for owner ", !l.isEmpty());   
    //delete contact
    adminUserDao.delete(contact, getUserId());
    l = adminUserDao.get(email, false);
    assertTrue("Contact list should be empty after deletion", l.isEmpty());

    User u = createUser(random.nextInt());
    User u1 = createUser(random.nextInt());
    contact = createUserContact(random.nextInt(), u.getUser_id());
    email = contact.getAdresses().getEmail();
    // check that contact is not visible for user that is not owner of this contact
    l = usersDao.get(email, u1.getUser_id());
    assertTrue("Contact list should be empty for another user", l.isEmpty());
    //delete contact
    adminUserDao.delete(contact, u.getUser_id());
    l = adminUserDao.get(email, false);
    assertTrue("Contact list should be empty after deletion", l.isEmpty());
  }
}
TOP

Related Classes of org.apache.openmeetings.test.user.TestUserContact

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.