Skip to content

Commit 36da5f9

Browse files
committed
test: channel and sever are rendered
1 parent 2ffe389 commit 36da5f9

File tree

4 files changed

+247
-2
lines changed

4 files changed

+247
-2
lines changed

demo/APIC-560/APIC-560.yaml

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
asyncapi: 2.0.0
2+
info:
3+
title: Streetlights API
4+
version: '1.0.0'
5+
description: |
6+
The Smartylighting Streetlights API allows you to remotely manage the city lights.
7+
8+
### Check out its awesome features:
9+
10+
* Turn a specific streetlight on/off 🌃
11+
* Dim a specific streetlight 😎
12+
* Receive real-time information about environmental lighting conditions 📈
13+
license:
14+
name: Apache 2.0
15+
url: https://www.apache.org/licenses/LICENSE-2.0
16+
17+
servers:
18+
production:
19+
url: api.streetlights.smartylighting.com:{port}
20+
protocol: mqtt
21+
description: Test broker
22+
variables:
23+
port:
24+
description: Secure connection (TLS) is available through port 8883.
25+
default: '1883'
26+
enum:
27+
- '1883'
28+
- '8883'
29+
security:
30+
- apiKey: []
31+
- supportedOauthFlows:
32+
- streetlights:on
33+
- streetlights:off
34+
- streetlights:dim
35+
- openIdConnectWellKnown: []
36+
37+
defaultContentType: application/json
38+
39+
channels:
40+
smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured:
41+
description: The topic on which measured values may be produced and consumed.
42+
parameters:
43+
streetlightId:
44+
$ref: '#/components/parameters/streetlightId'
45+
subscribe:
46+
summary: Receive information about environmental lighting conditions of a particular streetlight.
47+
operationId: receiveLightMeasurement
48+
traits:
49+
- $ref: '#/components/operationTraits/kafka'
50+
message:
51+
$ref: '#/components/messages/lightMeasured'
52+
53+
smartylighting/streetlights/1/0/action/{streetlightId}/turn/on:
54+
parameters:
55+
streetlightId:
56+
$ref: '#/components/parameters/streetlightId'
57+
publish:
58+
operationId: turnOn
59+
traits:
60+
- $ref: '#/components/operationTraits/kafka'
61+
message:
62+
$ref: '#/components/messages/turnOnOff'
63+
64+
smartylighting/streetlights/1/0/action/{streetlightId}/turn/off:
65+
parameters:
66+
streetlightId:
67+
$ref: '#/components/parameters/streetlightId'
68+
publish:
69+
operationId: turnOff
70+
traits:
71+
- $ref: '#/components/operationTraits/kafka'
72+
message:
73+
$ref: '#/components/messages/turnOnOff'
74+
75+
smartylighting/streetlights/1/0/action/{streetlightId}/dim:
76+
parameters:
77+
streetlightId:
78+
$ref: '#/components/parameters/streetlightId'
79+
publish:
80+
operationId: dimLight
81+
traits:
82+
- $ref: '#/components/operationTraits/kafka'
83+
message:
84+
$ref: '#/components/messages/dimLight'
85+
86+
components:
87+
messages:
88+
lightMeasured:
89+
name: lightMeasured
90+
title: Light measured
91+
summary: Inform about environmental lighting conditions for a particular streetlight.
92+
contentType: application/json
93+
traits:
94+
- $ref: '#/components/messageTraits/commonHeaders'
95+
payload:
96+
$ref: "#/components/schemas/lightMeasuredPayload"
97+
turnOnOff:
98+
name: turnOnOff
99+
title: Turn on/off
100+
summary: Command a particular streetlight to turn the lights on or off.
101+
traits:
102+
- $ref: '#/components/messageTraits/commonHeaders'
103+
payload:
104+
$ref: "#/components/schemas/turnOnOffPayload"
105+
dimLight:
106+
name: dimLight
107+
title: Dim light
108+
summary: Command a particular streetlight to dim the lights.
109+
traits:
110+
- $ref: '#/components/messageTraits/commonHeaders'
111+
payload:
112+
$ref: "#/components/schemas/dimLightPayload"
113+
114+
schemas:
115+
lightMeasuredPayload:
116+
type: object
117+
properties:
118+
lumens:
119+
type: integer
120+
minimum: 0
121+
description: Light intensity measured in lumens.
122+
sentAt:
123+
$ref: "#/components/schemas/sentAt"
124+
turnOnOffPayload:
125+
type: object
126+
properties:
127+
command:
128+
type: string
129+
enum:
130+
- on
131+
- off
132+
description: Whether to turn on or off the light.
133+
sentAt:
134+
$ref: "#/components/schemas/sentAt"
135+
dimLightPayload:
136+
type: object
137+
properties:
138+
percentage:
139+
type: integer
140+
description: Percentage to which the light should be dimmed to.
141+
minimum: 0
142+
maximum: 100
143+
sentAt:
144+
$ref: "#/components/schemas/sentAt"
145+
sentAt:
146+
type: string
147+
format: date-time
148+
description: Date and time when the message was sent.
149+
150+
securitySchemes:
151+
apiKey:
152+
type: apiKey
153+
in: user
154+
description: Provide your API key as the user and leave the password empty.
155+
supportedOauthFlows:
156+
type: oauth2
157+
description: Flows to support OAuth 2.0
158+
flows:
159+
implicit:
160+
authorizationUrl: 'https://authserver.example/auth'
161+
scopes:
162+
'streetlights:on': Ability to switch lights on
163+
'streetlights:off': Ability to switch lights off
164+
'streetlights:dim': Ability to dim the lights
165+
password:
166+
tokenUrl: 'https://authserver.example/token'
167+
scopes:
168+
'streetlights:on': Ability to switch lights on
169+
'streetlights:off': Ability to switch lights off
170+
'streetlights:dim': Ability to dim the lights
171+
clientCredentials:
172+
tokenUrl: 'https://authserver.example/token'
173+
scopes:
174+
'streetlights:on': Ability to switch lights on
175+
'streetlights:off': Ability to switch lights off
176+
'streetlights:dim': Ability to dim the lights
177+
authorizationCode:
178+
authorizationUrl: 'https://authserver.example/auth'
179+
tokenUrl: 'https://authserver.example/token'
180+
refreshUrl: 'https://authserver.example/refresh'
181+
scopes:
182+
'streetlights:on': Ability to switch lights on
183+
'streetlights:off': Ability to switch lights off
184+
'streetlights:dim': Ability to dim the lights
185+
openIdConnectWellKnown:
186+
type: openIdConnect
187+
openIdConnectUrl: 'https://authserver.example/.well-known'
188+
189+
parameters:
190+
streetlightId:
191+
description: The ID of the streetlight.
192+
schema:
193+
type: string
194+
195+
messageTraits:
196+
commonHeaders:
197+
headers:
198+
type: object
199+
properties:
200+
my-app-header:
201+
type: integer
202+
minimum: 0
203+
maximum: 100
204+
205+
operationTraits:
206+
kafka:
207+
bindings:
208+
kafka:
209+
clientId: my-app-id

demo/apis.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"oas-callbacks/oas-callbacks.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
1212
"multi-server/multi-server.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
1313
"async-api/async-api.yaml": "ASYNC 2.0",
14-
"APIC-553/APIC-553.raml": "RAML 1.0"
14+
"APIC-553/APIC-553.raml": "RAML 1.0",
15+
"APIC-560/APIC-560.yaml": "ASYNC 2.0"
1516
}

demo/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class ComponentDemo extends ApiDemoPage {
162162
['SE-12752', 'Query string (SE-12752)'],
163163
['oas-callbacks', 'OAS 3 callbacks'],
164164
['async-api', 'Async API'],
165+
['APIC-560', 'APIC-560'],
165166
].map(([file, label]) => html`
166167
<anypoint-item data-src="${file}-compact.json">${label} - compact model</anypoint-item>
167168
<anypoint-item data-src="${file}.json">${label}</anypoint-item>

test/api-url.test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('<api-url>', function () {
2323
element.baseUri = 'http://example.org';
2424
await nextFrame();
2525
assert.equal(element.url, 'http://example.org');
26-
assert.equal(element.shadowRoot.querySelector('.url-value').textContent, 'http://example.org');
26+
assert.equal(element.shadowRoot.querySelector('.url-value').textContent.trim(), 'http://example.org');
2727
});
2828
});
2929

@@ -119,6 +119,40 @@ describe('<api-url>', function () {
119119
assert.equal(element._method, 'PUBLISH');
120120
});
121121
});
122+
123+
describe('APIC-560', () => {
124+
let amf;
125+
let element;
126+
let server;
127+
128+
before(async () => {
129+
amf = await AmfLoader.load('APIC-560', compact);
130+
});
131+
132+
beforeEach(async () => {
133+
const endpointName = 'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured'
134+
const [endpoint, operation] = AmfLoader.lookupEndpointOperation(amf, endpointName, 'subscribe');
135+
element = await basicFixture();
136+
element.amf = amf;
137+
server = AmfLoader.getEncodes(amf)[element._getAmfKey(element.ns.aml.vocabularies.apiContract.server)];
138+
if (Array.isArray(server)) {
139+
server = server[0];
140+
}
141+
element = await operationFixture({ amf, endpoint, operation, server });
142+
// model change debouncer
143+
await nextFrame();
144+
});
145+
146+
it('should render channel', () => {
147+
const channel = 'Channelsmartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured'
148+
assert.equal(element.shadowRoot.querySelector('.url-channel-value').textContent, channel);
149+
});
150+
151+
it('should render server', () => {
152+
const server = 'Servermqtt://api.streetlights.smartylighting.com:{port}'
153+
assert.equal(element.shadowRoot.querySelector('.url-server-value').textContent, server);
154+
});
155+
});
122156
});
123157
});
124158
});

0 commit comments

Comments
 (0)