package com.devicehive.dao;
/*
* #%L
* DeviceHive Dao Riak Implementation
* %%
* Copyright (C) 2016 DataArt
* %%
* Licensed 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.
* #L%
*/
import com.devicehive.dao.riak.UserNetworkDaoRiakImpl;
import com.devicehive.dao.riak.model.UserNetwork;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Set;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class UserNetworkDaoTest {
@Autowired(required = false)
UserNetworkDaoRiakImpl userNetworkDao;
@Autowired
ApplicationContext ctx;
@Before
public void beforeMethod() {
org.junit.Assume.assumeTrue(ctx.getEnvironment().acceptsProfiles("riak"));
}
@Test
public void testRetrieval() throws Exception {
UserNetwork un1 = new UserNetwork();
un1.setUserId(1L);
un1.setNetworkId(64L);
userNetworkDao.persist(un1);
UserNetwork un2 = new UserNetwork();
un2.setUserId(1L);
un2.setNetworkId(65L);
userNetworkDao.persist(un2);
UserNetwork un3 = new UserNetwork();
un3.setUserId(2L);
un3.setNetworkId(64L);
userNetworkDao.persist(un3);
Set<Long> networks1 = userNetworkDao.findNetworksForUser(1L);
assertNotNull(networks1);
assertTrue(networks1.contains(64L));
assertTrue(networks1.contains(65L));
Set<Long> users1 = userNetworkDao.findUsersInNetwork(64L);
assertNotNull(users1);
assertTrue(users1.contains(1L));
assertTrue(users1.contains(2L));
}
}