mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
QQQ-16 some cleanup and increased test cover
This commit is contained in:
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* QQQ - Low-code Application Framework for Engineers.
|
||||||
|
* Copyright (C) 2021-2022. Kingsrook, LLC
|
||||||
|
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||||
|
* contact@kingsrook.com
|
||||||
|
* https://github.com/Kingsrook/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.kingsrook.qqq.backend.core.callbacks;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.query.QQueryFilter;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.QFieldMetaData;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Simple implementation of a callback, that does no-op (returns empty objects).
|
||||||
|
** Useful for scaffolding, perhaps tests.
|
||||||
|
*******************************************************************************/
|
||||||
|
public class NoopCallback implements QProcessCallback
|
||||||
|
{
|
||||||
|
/*******************************************************************************
|
||||||
|
** Get the filter query for this callback.
|
||||||
|
*******************************************************************************/
|
||||||
|
@Override
|
||||||
|
public QQueryFilter getQueryFilter()
|
||||||
|
{
|
||||||
|
return (new QQueryFilter());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Get the field values for this callback.
|
||||||
|
*******************************************************************************/
|
||||||
|
@Override
|
||||||
|
public Map<String, Serializable> getFieldValues(List<QFieldMetaData> fields)
|
||||||
|
{
|
||||||
|
return (Collections.emptyMap());
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,7 @@
|
|||||||
package com.kingsrook.qqq.backend.core.model.metadata;
|
package com.kingsrook.qqq.backend.core.model.metadata;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ import java.util.Map;
|
|||||||
** Meta-Data to define a table in a QQQ instance.
|
** Meta-Data to define a table in a QQQ instance.
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public class QTableMetaData
|
public class QTableMetaData implements Serializable
|
||||||
{
|
{
|
||||||
private String name;
|
private String name;
|
||||||
private String label;
|
private String label;
|
||||||
|
@ -27,18 +27,14 @@ import java.util.UUID;
|
|||||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
||||||
import com.kingsrook.qqq.backend.core.model.session.QUser;
|
import com.kingsrook.qqq.backend.core.model.session.QUser;
|
||||||
import com.kingsrook.qqq.backend.core.modules.interfaces.QAuthenticationModuleInterface;
|
import com.kingsrook.qqq.backend.core.modules.interfaces.QAuthenticationModuleInterface;
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
** An authentication module with no actual backing system - all users are treated
|
||||||
|
** as anonymous, and all sessions are always valid.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public class FullyAnonymousAuthenticationModule implements QAuthenticationModuleInterface
|
public class FullyAnonymousAuthenticationModule implements QAuthenticationModuleInterface
|
||||||
{
|
{
|
||||||
private static final Logger logger = LogManager.getLogger(FullyAnonymousAuthenticationModule.class);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
@ -51,7 +47,7 @@ public class FullyAnonymousAuthenticationModule implements QAuthenticationModule
|
|||||||
qUser.setFullName("Anonymous");
|
qUser.setFullName("Anonymous");
|
||||||
|
|
||||||
QSession qSession = new QSession();
|
QSession qSession = new QSession();
|
||||||
if (context.get("sessionId") != null)
|
if(context != null && context.get("sessionId") != null)
|
||||||
{
|
{
|
||||||
qSession.setIdReference(context.get("sessionId"));
|
qSession.setIdReference(context.get("sessionId"));
|
||||||
}
|
}
|
||||||
@ -72,6 +68,10 @@ public class FullyAnonymousAuthenticationModule implements QAuthenticationModule
|
|||||||
@Override
|
@Override
|
||||||
public boolean isSessionValid(QSession session)
|
public boolean isSessionValid(QSession session)
|
||||||
{
|
{
|
||||||
|
if(session == null)
|
||||||
|
{
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ package com.kingsrook.qqq.backend.core.state;
|
|||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||||
@ -30,7 +31,7 @@ import org.apache.commons.io.FileUtils;
|
|||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Singleton class that provides a (non-persistent!!) in-memory state provider.
|
** State provider that uses files in the /tmp/ directory.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public class TempFileStateProvider implements StateProviderInterface
|
public class TempFileStateProvider implements StateProviderInterface
|
||||||
{
|
{
|
||||||
@ -92,9 +93,9 @@ public class TempFileStateProvider implements StateProviderInterface
|
|||||||
String json = FileUtils.readFileToString(new File("/tmp/" + key.toString()));
|
String json = FileUtils.readFileToString(new File("/tmp/" + key.toString()));
|
||||||
return JsonUtils.toObject(json, type);
|
return JsonUtils.toObject(json, type);
|
||||||
}
|
}
|
||||||
catch(ClassCastException cce)
|
catch(FileNotFoundException fnfe)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Stored state value could not be cast to desired type", cce);
|
return (null);
|
||||||
}
|
}
|
||||||
catch(IOException ie)
|
catch(IOException ie)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* QQQ - Low-code Application Framework for Engineers.
|
||||||
|
* Copyright (C) 2021-2022. Kingsrook, LLC
|
||||||
|
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||||
|
* contact@kingsrook.com
|
||||||
|
* https://github.com/Kingsrook/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.kingsrook.qqq.backend.core.modules.defaults;
|
||||||
|
|
||||||
|
|
||||||
|
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Unit test for the FullyAnonymousAuthenticationModule
|
||||||
|
*******************************************************************************/
|
||||||
|
public class FullyAnonymousAuthenticationModuleTest
|
||||||
|
{
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test()
|
||||||
|
{
|
||||||
|
FullyAnonymousAuthenticationModule fullyAnonymousAuthenticationModule = new FullyAnonymousAuthenticationModule();
|
||||||
|
|
||||||
|
QSession session = fullyAnonymousAuthenticationModule.createSession(null);
|
||||||
|
|
||||||
|
assertNotNull(session, "Session should not be null");
|
||||||
|
assertNotNull(session.getIdReference(), "Session id ref should not be null");
|
||||||
|
assertNotNull(session.getUser(), "Session User should not be null");
|
||||||
|
assertNotNull(session.getUser().getIdReference(), "Session User id ref should not be null");
|
||||||
|
assertTrue(fullyAnonymousAuthenticationModule.isSessionValid(session), "Any session should be valid");
|
||||||
|
assertFalse(fullyAnonymousAuthenticationModule.isSessionValid(null), "null should be not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* QQQ - Low-code Application Framework for Engineers.
|
||||||
|
* Copyright (C) 2021-2022. Kingsrook, LLC
|
||||||
|
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||||
|
* contact@kingsrook.com
|
||||||
|
* https://github.com/Kingsrook/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.kingsrook.qqq.backend.core.state;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.QTableMetaData;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Unit test for InMemoryStateProvider
|
||||||
|
*******************************************************************************/
|
||||||
|
public class InMemoryStateProviderTest
|
||||||
|
{
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
public void testStateNotFound()
|
||||||
|
{
|
||||||
|
InMemoryStateProvider stateProvider = InMemoryStateProvider.getInstance();
|
||||||
|
UUIDStateKey key = new UUIDStateKey();
|
||||||
|
|
||||||
|
Assertions.assertNull(stateProvider.get(QRecord.class, key), "Key not found in state should return null");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
public void testSimpleStateFound()
|
||||||
|
{
|
||||||
|
InMemoryStateProvider stateProvider = InMemoryStateProvider.getInstance();
|
||||||
|
UUIDStateKey key = new UUIDStateKey();
|
||||||
|
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
QRecord qRecord = new QRecord().withValue("uuid", uuid);
|
||||||
|
stateProvider.put(key, qRecord);
|
||||||
|
|
||||||
|
QRecord qRecordFromState = stateProvider.get(QRecord.class, key);
|
||||||
|
Assertions.assertEquals(uuid, qRecordFromState.getValueString("uuid"), "Should read value from state persistence");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
public void testWrongTypeOnGet()
|
||||||
|
{
|
||||||
|
InMemoryStateProvider stateProvider = InMemoryStateProvider.getInstance();
|
||||||
|
UUIDStateKey key = new UUIDStateKey();
|
||||||
|
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
QRecord qRecord = new QRecord().withValue("uuid", uuid);
|
||||||
|
stateProvider.put(key, qRecord);
|
||||||
|
|
||||||
|
Assertions.assertThrows(Exception.class, () ->
|
||||||
|
{
|
||||||
|
stateProvider.get(QTableMetaData.class, key);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* QQQ - Low-code Application Framework for Engineers.
|
||||||
|
* Copyright (C) 2021-2022. Kingsrook, LLC
|
||||||
|
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||||
|
* contact@kingsrook.com
|
||||||
|
* https://github.com/Kingsrook/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.kingsrook.qqq.backend.core.state;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.QTableMetaData;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Unit test for TempFileStateProvider
|
||||||
|
*******************************************************************************/
|
||||||
|
public class TempFileStateProviderTest
|
||||||
|
{
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
public void testStateNotFound()
|
||||||
|
{
|
||||||
|
TempFileStateProvider stateProvider = TempFileStateProvider.getInstance();
|
||||||
|
UUIDStateKey key = new UUIDStateKey();
|
||||||
|
|
||||||
|
Assertions.assertNull(stateProvider.get(QRecord.class, key), "Key not found in state should return null");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
public void testSimpleStateFound()
|
||||||
|
{
|
||||||
|
TempFileStateProvider stateProvider = TempFileStateProvider.getInstance();
|
||||||
|
UUIDStateKey key = new UUIDStateKey();
|
||||||
|
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
QRecord qRecord = new QRecord().withValue("uuid", uuid);
|
||||||
|
stateProvider.put(key, qRecord);
|
||||||
|
|
||||||
|
QRecord qRecordFromState = stateProvider.get(QRecord.class, key);
|
||||||
|
Assertions.assertEquals(uuid, qRecordFromState.getValueString("uuid"), "Should read value from state persistence");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
public void testWrongTypeOnGet()
|
||||||
|
{
|
||||||
|
TempFileStateProvider stateProvider = TempFileStateProvider.getInstance();
|
||||||
|
UUIDStateKey key = new UUIDStateKey();
|
||||||
|
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
QRecord qRecord = new QRecord().withValue("uuid", uuid);
|
||||||
|
stateProvider.put(key, qRecord);
|
||||||
|
|
||||||
|
Assertions.assertThrows(Exception.class, () ->
|
||||||
|
{
|
||||||
|
stateProvider.get(QTableMetaData.class, key);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user