08 01 25
Список каналов возвращает - хотя сырое всё как то - но всё работает :)
This commit is contained in:
parent
aba86fc687
commit
9d0da4b39f
@ -42,14 +42,14 @@ public final class MsgSubType {
|
|||||||
public static final short CONNECTION_UNFRIEND = 11;
|
public static final short CONNECTION_UNFRIEND = 11;
|
||||||
|
|
||||||
/** Подписаться (follow). */
|
/** Подписаться (follow). */
|
||||||
public static final short CONNECTION_FOLLOW = 20;
|
public static final short CONNECTION_FOLLOW = 30;
|
||||||
|
|
||||||
/** Отписаться (unfollow). */
|
/** Отписаться (unfollow). */
|
||||||
public static final short CONNECTION_UNFOLLOW = 21;
|
public static final short CONNECTION_UNFOLLOW = 31;
|
||||||
|
//
|
||||||
/** Заблокировать. */
|
// /** Заблокировать. */
|
||||||
public static final short CONNECTION_BLOCK = 30;
|
// public static final short CONNECTION_BLOCK = 30;
|
||||||
|
//
|
||||||
/** Разблокировать. */
|
// /** Разблокировать. */
|
||||||
public static final short CONNECTION_UNBLOCK = 31;
|
// public static final short CONNECTION_UNBLOCK = 31;
|
||||||
}
|
}
|
||||||
@ -23,52 +23,56 @@ import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_GetUserPar
|
|||||||
import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_ListUserParams_Request;
|
import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_ListUserParams_Request;
|
||||||
import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_UpsertUserParam_Request;
|
import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_UpsertUserParam_Request;
|
||||||
|
|
||||||
|
// !!! подставь реальные пакеты/имена, как у тебя в проекте:
|
||||||
|
import server.logic.ws_protocol.JSON.handlers.subscriptions.Net_GetSubscribedChannels_Handler;
|
||||||
|
import server.logic.ws_protocol.JSON.handlers.subscriptions.entyties.Net_GetSubscribedChannels_Request;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JsonHandlerRegistry — единое место, где руками регистрируются
|
* JsonHandlerRegistry — единое место, где руками регистрируются
|
||||||
* JSON-операции: op → handler и op → requestClass.
|
* JSON-операции: op → handler и op → requestClass.
|
||||||
*
|
|
||||||
* Если нужно добавить новый запрос:
|
|
||||||
* 1) создаёшь класс NetXXXRequest / NetXXXResponse,
|
|
||||||
* 2) создаёшь JsonMessageHandler (NetXXXHandler),
|
|
||||||
* 3) добавляешь op в HANDLERS и REQUEST_TYPES.
|
|
||||||
*/
|
*/
|
||||||
public final class JsonHandlerRegistry {
|
public final class JsonHandlerRegistry {
|
||||||
|
|
||||||
private static final Map<String, JsonMessageHandler> HANDLERS = Map.of(
|
// Map.of(...) поддерживает максимум 10 пар => используем Map.ofEntries(...)
|
||||||
"RefreshSession", new Net_RefreshSession_Handler(),
|
private static final Map<String, JsonMessageHandler> HANDLERS = Map.ofEntries(
|
||||||
"AddUser", new Net_AddUser_Handler(),
|
Map.entry("RefreshSession", new Net_RefreshSession_Handler()),
|
||||||
"AuthChallenge", new Net_AuthChallenge_Handler(),
|
Map.entry("AddUser", new Net_AddUser_Handler()),
|
||||||
"CreateAuthSession", new Net_CreateAuthSession__Handler(),
|
Map.entry("AuthChallenge", new Net_AuthChallenge_Handler()),
|
||||||
"CloseActiveSession", new Net_CloseActiveSession_Handler(),
|
Map.entry("CreateAuthSession", new Net_CreateAuthSession__Handler()),
|
||||||
"ListSessions", new Net_ListSessions_Handler(),
|
Map.entry("CloseActiveSession", new Net_CloseActiveSession_Handler()),
|
||||||
"AddBlock", new Net_AddBlock_Handler(),
|
Map.entry("ListSessions", new Net_ListSessions_Handler()),
|
||||||
|
Map.entry("AddBlock", new Net_AddBlock_Handler()),
|
||||||
|
|
||||||
// --- userParams ---
|
// --- userParams ---
|
||||||
"UpsertUserParam", new Net_UpsertUserParam_Handler(),
|
Map.entry("UpsertUserParam", new Net_UpsertUserParam_Handler()),
|
||||||
"GetUserParam", new Net_GetUserParam_Handler(),
|
Map.entry("GetUserParam", new Net_GetUserParam_Handler()),
|
||||||
"ListUserParams", new Net_ListUserParams_Handler()
|
Map.entry("ListUserParams", new Net_ListUserParams_Handler()),
|
||||||
|
|
||||||
|
// --- subscriptions ---
|
||||||
|
Map.entry("ListSubscribedChannels", new Net_GetSubscribedChannels_Handler())
|
||||||
);
|
);
|
||||||
|
|
||||||
private static final Map<String, Class<? extends Net_Request>> REQUEST_TYPES = Map.of(
|
private static final Map<String, Class<? extends Net_Request>> REQUEST_TYPES = Map.ofEntries(
|
||||||
"RefreshSession", Net_RefreshSession_Request.class,
|
Map.entry("RefreshSession", Net_RefreshSession_Request.class),
|
||||||
"AddUser", Net_AddUser_Request.class,
|
Map.entry("AddUser", Net_AddUser_Request.class),
|
||||||
"AuthChallenge", Net_AuthChallenge_Request.class,
|
Map.entry("AuthChallenge", Net_AuthChallenge_Request.class),
|
||||||
"CreateAuthSession", Net_CreateAuthSession_Request.class,
|
Map.entry("CreateAuthSession", Net_CreateAuthSession_Request.class),
|
||||||
"CloseActiveSession", Net_CloseActiveSession_Request.class,
|
Map.entry("CloseActiveSession", Net_CloseActiveSession_Request.class),
|
||||||
"ListSessions", Net_ListSessions_Request.class,
|
Map.entry("ListSessions", Net_ListSessions_Request.class),
|
||||||
"AddBlock", Net_AddBlock_Request.class,
|
Map.entry("AddBlock", Net_AddBlock_Request.class),
|
||||||
|
|
||||||
// --- userParams ---
|
// --- userParams ---
|
||||||
"UpsertUserParam", Net_UpsertUserParam_Request.class,
|
Map.entry("UpsertUserParam", Net_UpsertUserParam_Request.class),
|
||||||
"GetUserParam", Net_GetUserParam_Request.class,
|
Map.entry("GetUserParam", Net_GetUserParam_Request.class),
|
||||||
"ListUserParams", Net_ListUserParams_Request.class
|
Map.entry("ListUserParams", Net_ListUserParams_Request.class),
|
||||||
|
|
||||||
|
// --- subscriptions ---
|
||||||
|
Map.entry("ListSubscribedChannels", Net_GetSubscribedChannels_Request.class)
|
||||||
);
|
);
|
||||||
|
|
||||||
private JsonHandlerRegistry() {
|
private JsonHandlerRegistry() { }
|
||||||
// utility
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, JsonMessageHandler> getHandlers() {
|
public static Map<String, JsonMessageHandler> getHandlers() {
|
||||||
return HANDLERS;
|
return HANDLERS;
|
||||||
|
|||||||
@ -37,15 +37,24 @@ public class IT_03_AddBlock_NoAuth {
|
|||||||
|
|
||||||
String u1 = TestConfig.LOGIN();
|
String u1 = TestConfig.LOGIN();
|
||||||
String u2 = TestConfig.LOGIN2();
|
String u2 = TestConfig.LOGIN2();
|
||||||
|
String u3 = TestConfig.LOGIN3();
|
||||||
|
|
||||||
String bch1 = TestConfig.getBlockchainName(u1);
|
String bch1 = TestConfig.getBlockchainName(u1);
|
||||||
String bch2 = TestConfig.getBlockchainName(u2);
|
String bch2 = TestConfig.getBlockchainName(u2);
|
||||||
|
String bch3 = TestConfig.getBlockchainName(u3);
|
||||||
|
|
||||||
Duration t = Duration.ofSeconds(1);
|
Duration t = Duration.ofSeconds(1);
|
||||||
|
|
||||||
try (WsSession ws = WsSession.open()) {
|
try (WsSession ws = WsSession.open()) {
|
||||||
|
|
||||||
if (TestConfig.DEBUG()) TestLog.titleBlock("IT_03: USER1=" + u1 + " bch=" + bch1 + " | USER2=" + u2 + " bch=" + bch2);
|
if (TestConfig.DEBUG()) {
|
||||||
|
TestLog.titleBlock(
|
||||||
|
"IT_03:\n" +
|
||||||
|
" USER1=" + u1 + " bch=" + bch1 + "\n" +
|
||||||
|
" USER2=" + u2 + " bch=" + bch2 + "\n" +
|
||||||
|
" USER3=" + u3 + " bch=" + bch3
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// USER1
|
// USER1
|
||||||
ChainState st1 = new ChainState();
|
ChainState st1 = new ChainState();
|
||||||
@ -88,11 +97,33 @@ public class IT_03_AddBlock_NoAuth {
|
|||||||
|
|
||||||
sender2.send(new UserParamBody("Anya", "Amsterdam, Example street 10"), t);
|
sender2.send(new UserParamBody("Anya", "Amsterdam, Example street 10"), t);
|
||||||
|
|
||||||
|
// USER3 (нужен, чтобы u1 мог подписаться на существующий блокчейн)
|
||||||
|
ChainState st3 = new ChainState();
|
||||||
|
AddBlockSender sender3 = new AddBlockSender(ws, st3, u3, bch3, TestConfig.getBlockchainPrivatKey(u3));
|
||||||
|
|
||||||
|
sender3.send(new HeaderBody(u3), t);
|
||||||
|
assertTrue(st3.hasHeader());
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
// Подписки (как ты просил):
|
||||||
|
// - u1 follows u2 и u3
|
||||||
|
// - u2 follows только u1
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
|
||||||
|
// u1 -> follow u2
|
||||||
|
sender1.send(new ConnectionBody(ConnectionBody.SUB_FOLLOW, u2, bch2, 0, new byte[32]), t);
|
||||||
|
|
||||||
|
// u1 -> follow u3
|
||||||
|
sender1.send(new ConnectionBody(ConnectionBody.SUB_FOLLOW, u3, bch3, 0, new byte[32]), t);
|
||||||
|
|
||||||
|
// u2 -> follow u1
|
||||||
|
sender2.send(new ConnectionBody(ConnectionBody.SUB_FOLLOW, u1, bch1, 0, new byte[32]), t);
|
||||||
|
|
||||||
|
// (оставил твои friend/unfriend как было — но они уже не обязательны для подписок)
|
||||||
sender2.send(new ConnectionBody(ConnectionBody.SUB_FRIEND, u1, bch1, 0, new byte[32]), t);
|
sender2.send(new ConnectionBody(ConnectionBody.SUB_FRIEND, u1, bch1, 0, new byte[32]), t);
|
||||||
|
|
||||||
sender1.send(new UserParamBody("Anna", "Gareeva"), t);
|
sender1.send(new UserParamBody("Anna", "Gareeva"), t);
|
||||||
sender1.send(new ConnectionBody(ConnectionBody.SUB_FRIEND, u2, bch2, 0, new byte[32]), t);
|
sender1.send(new ConnectionBody(ConnectionBody.SUB_FRIEND, u2, bch2, 0, new byte[32]), t);
|
||||||
sender1.send(new ConnectionBody(ConnectionBody.SUB_FOLLOW, u2, bch2, 0, new byte[32]), t);
|
|
||||||
|
|
||||||
sender2.send(new ConnectionBody(ConnectionBody.SUB_UNFRIEND, u1, bch1, 0, new byte[32]), t);
|
sender2.send(new ConnectionBody(ConnectionBody.SUB_UNFRIEND, u1, bch1, 0, new byte[32]), t);
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import test.it.cases.IT_01_AddUser;
|
|||||||
import test.it.cases.IT_02_Sessions;
|
import test.it.cases.IT_02_Sessions;
|
||||||
import test.it.cases.IT_03_AddBlock_NoAuth;
|
import test.it.cases.IT_03_AddBlock_NoAuth;
|
||||||
import test.it.cases.IT_04_UserParams_NoAuth;
|
import test.it.cases.IT_04_UserParams_NoAuth;
|
||||||
|
import test.it.cases.IT_05_ListSubscribedChannels_200;
|
||||||
import test.it.utils.log.TestLog;
|
import test.it.utils.log.TestLog;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -17,7 +18,6 @@ public class IT_RunAllMain {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int failed = runAll();
|
int failed = runAll();
|
||||||
System.exit(failed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int runAll() {
|
public static int runAll() {
|
||||||
@ -31,6 +31,7 @@ public class IT_RunAllMain {
|
|||||||
String s2 = IT_02_Sessions.run(); summaries.add(s2); if (s2.contains("FAIL:")) failed++;
|
String s2 = IT_02_Sessions.run(); summaries.add(s2); if (s2.contains("FAIL:")) failed++;
|
||||||
String s3 = IT_03_AddBlock_NoAuth.run(); summaries.add(s3); if (s3.contains("FAIL:")) failed++;
|
String s3 = IT_03_AddBlock_NoAuth.run(); summaries.add(s3); if (s3.contains("FAIL:")) failed++;
|
||||||
String s4 = IT_04_UserParams_NoAuth.run(); summaries.add(s4); if (s4.contains("FAIL:")) failed++;
|
String s4 = IT_04_UserParams_NoAuth.run(); summaries.add(s4); if (s4.contains("FAIL:")) failed++;
|
||||||
|
String s5 = IT_05_ListSubscribedChannels_200.run(); summaries.add(s5); if (s5.contains("FAIL:")) failed++;
|
||||||
|
|
||||||
TestLog.title("IT RUN RESULT (per test)");
|
TestLog.title("IT RUN RESULT (per test)");
|
||||||
for (String s : summaries) System.out.println(s);
|
for (String s : summaries) System.out.println(s);
|
||||||
|
|||||||
@ -132,6 +132,20 @@ public final class JsonBuilders {
|
|||||||
""".formatted(requestId, sessionId, timeMs, signatureB64);
|
""".formatted(requestId, sessionId, timeMs, signatureB64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------- ListSubscribedChannels ----------------
|
||||||
|
|
||||||
|
public static String listSubscribedChannels(String login) {
|
||||||
|
String requestId = TestIds.next("subs");
|
||||||
|
return """
|
||||||
|
{
|
||||||
|
"op": "ListSubscribedChannels",
|
||||||
|
"requestId": "%s",
|
||||||
|
"payload": { "login": "%s" }
|
||||||
|
}
|
||||||
|
""".formatted(requestId, login);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Подпись для режима AUTH_IN_PROGRESS:
|
* Подпись для режима AUTH_IN_PROGRESS:
|
||||||
* preimage = "AUTHORIFICATED:" + timeMs + authNonce
|
* preimage = "AUTHORIFICATED:" + timeMs + authNonce
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user