|
| 1 | +/* |
| 2 | + * TeleStax, Open Source Cloud Communications |
| 3 | + * Copyright 2011-2014, Telestax Inc and individual contributors |
| 4 | + * by the @authors tag. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * under the terms of the GNU Affero General Public License as |
| 8 | + * published by the Free Software Foundation; either version 3 of |
| 9 | + * the License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU Affero General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Affero General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 18 | + * |
| 19 | + */ |
| 20 | + |
| 21 | +package org.restcomm.connect.dao.mybatis; |
| 22 | + |
| 23 | +import junit.framework.Assert; |
| 24 | +import org.apache.ibatis.session.SqlSessionFactory; |
| 25 | +import org.apache.ibatis.session.SqlSessionFactoryBuilder; |
| 26 | +import org.junit.After; |
| 27 | +import org.junit.Before; |
| 28 | +import org.junit.Test; |
| 29 | +import org.restcomm.connect.dao.IncomingPhoneNumbersDao; |
| 30 | +import org.restcomm.connect.dao.entities.IncomingPhoneNumber; |
| 31 | +import org.restcomm.connect.dao.entities.IncomingPhoneNumberFilter; |
| 32 | + |
| 33 | +import java.io.FileInputStream; |
| 34 | +import java.io.InputStream; |
| 35 | +import java.util.List; |
| 36 | + |
| 37 | +/** |
| 38 | + * @author otsakir@gmail.com - Orestis Tsakiridis |
| 39 | + */ |
| 40 | +public class IncomingPhoneNumbersRetrievalTest extends DaoTest { |
| 41 | + private static MybatisDaoManager manager; |
| 42 | + |
| 43 | + @Before |
| 44 | + public void before() throws Exception { |
| 45 | + sandboxRoot = createTempDir("IncomingPhoneNumbersRetrievalTest"); |
| 46 | + String mybatisFilesPath = getClass().getResource("/applicationsDao").getFile(); |
| 47 | + setupSandbox(mybatisFilesPath, sandboxRoot); |
| 48 | + |
| 49 | + String mybatisXmlPath = sandboxRoot.getPath() + "/mybatis_updated.xml"; |
| 50 | + final InputStream data = new FileInputStream(mybatisXmlPath); |
| 51 | + final SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); |
| 52 | + final SqlSessionFactory factory = builder.build(data); |
| 53 | + manager = new MybatisDaoManager(); |
| 54 | + manager.start(factory); |
| 55 | + } |
| 56 | + |
| 57 | + @After |
| 58 | + public void after() throws Exception { |
| 59 | + manager.shutdown(); |
| 60 | + removeTempDir(sandboxRoot.getAbsolutePath()); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void retrieveNumbersForApplication() { |
| 65 | + IncomingPhoneNumbersDao dao = manager.getIncomingPhoneNumbersDao(); |
| 66 | + // application AP73926e7113fa4d95981aa96b76eca854 is bound with 3 numbers |
| 67 | + IncomingPhoneNumberFilter filter = new IncomingPhoneNumberFilter("ACae6e420f425248d6a26948c17a9e2acf", null, null, "AP73926e7113fa4d95981aa96b76eca854", null, null, 100, 0); |
| 68 | + List<IncomingPhoneNumber> numbers = dao.getIncomingPhoneNumbersByFilter(filter); |
| 69 | + Assert.assertEquals(3, numbers.size()); |
| 70 | + // application AP00000000000000000000000000000004 is bound with no numbers |
| 71 | + filter = new IncomingPhoneNumberFilter("ACae6e420f425248d6a26948c17a9e2acf", null, null, "AP00000000000000000000000000000004", null, null, 100, 0); |
| 72 | + numbers = dao.getIncomingPhoneNumbersByFilter(filter); |
| 73 | + Assert.assertEquals(0, numbers.size()); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public void countTotalNumbersForApplication() { |
| 78 | + IncomingPhoneNumbersDao dao = manager.getIncomingPhoneNumbersDao(); |
| 79 | + IncomingPhoneNumberFilter filter = new IncomingPhoneNumberFilter("ACae6e420f425248d6a26948c17a9e2acf", null, null, "AP73926e7113fa4d95981aa96b76eca854", null, null, 100, 0); |
| 80 | + int total = dao.getTotalIncomingPhoneNumbers(filter); |
| 81 | + Assert.assertEquals(3, total); |
| 82 | + } |
| 83 | + |
| 84 | +} |
0 commit comments